skeleton.
Juan Batiz-Benet committed
Jun 26, 2014 at 01:14 UTC
3b570d3f82d2334dc9d8696acb0a8253eb9ce4e3
14 files changed
+242
README.md
new
+10
@@ -0,0 +1,10 @@
1
+# ipfs implementation in go.
2
+
3
+See: https://github.com/jbenet/ipfs
4
+
5
+Please put all issues regarding IPFS _design_ in the
6
+[ipfs repo issues](https://github.com/jbenet/ipfs/issues).
7
+
8
+Please put all issues regarding go IPFS _implementation_ in [this repo](https://github.com/jbenet/go-ipfs/issues).
9
+
10
+The [node implementation](https://github.com/jbenet/node-ipfs) is much farther along. This one is just a skeleton.
bitswap/bitswap.go
new
+17
@@ -0,0 +1,17 @@
1
+package bitswap
2
+
3
+import (
4
+ "github.com/jbenet/go-ipfs/peer"
5
+)
6
+
7
+// aliases
8
+
9
+type Ledger struct {
10
+ // todo
11
+}
12
+
13
+type BitSwap struct {
14
+ Ledgers map[peer.PeerId]*Ledger
15
+ HaveList map[multihash.Multihash]*block.Block
16
+ WantList []*multihash.Multihash
17
+}
block/block.go
new
+10
@@ -0,0 +1,10 @@
1
+package block
2
+
3
+import (
4
+ "github.com/jbenet/go-multihash"
5
+)
6
+
7
+type Block struct {
8
+ Multihash []byte
9
+ Data []byte
10
+}
blocks/blocks.go
new
+14
@@ -0,0 +1,14 @@
1
+package blocks
2
+
3
+import (
4
+ "github.com/jbenet/go-ipfs/bitswap"
5
+ "github.com/jbenet/go-ipfs/storage"
6
+)
7
+
8
+// Blocks is the ipfs blocks service. It is the way
9
+// to retrieve blocks by the higher level ipfs modules
10
+
11
+type BlockService struct {
12
+ Local *storage.Storage
13
+ Remote *bitswap.BitSwap
14
+}
core/core.go
new
+33
@@ -0,0 +1,33 @@
1
+package core
2
+
3
+// IPFS Core module. It represents an IPFS instance.
4
+
5
+type IPFSNode struct {
6
+
7
+ // the local node's identity (a Peer instance)
8
+ Identity *peer.Peer
9
+
10
+ // the book of other nodes (a hashtable of Peer instances)
11
+ PeerBook *peerbook.PeerBook
12
+
13
+ // the local database (uses datastore)
14
+ Storage *storage.Storage
15
+
16
+ // the network message stream
17
+ Network *netmux.Netux
18
+
19
+ // the routing system. recommend ipfs-dht
20
+ Routing *routing.Routing
21
+
22
+ // the block exchange + strategy (bitswap)
23
+ BitSwap *bitswap.BitSwap
24
+
25
+ // the block service, get/add blocks.
26
+ Blocks *blocks.BlockService
27
+
28
+ // the path resolution system
29
+ Resolver *resolver.PathResolver
30
+
31
+ // the name system, resolves paths to hashes
32
+ Namesys *namesys.Namesys
33
+}
dht/dht.go
new
+7
@@ -0,0 +1,7 @@
1
+package dht
2
+
3
+// The IPFS DHT is an implementation of Kademlia with
4
+// Coral and S/Kademlia modifications. It is used to
5
+// implement the base IPFS Routing module.
6
+
7
+TODO. SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-dht/index.js
msgproto/msgproto.go
netmux/interface.go
new
+96
@@ -0,0 +1,96 @@
1
+package netmux
2
+
3
+import (
4
+ "net"
5
+)
6
+
7
+// An interface is the module connecting netmux
8
+// to various networks (tcp, udp, webrtc, etc).
9
+// It keeps the relevant connections open.
10
+type Interface struct {
11
+
12
+ // Interface network (e.g. udp4, tcp6)
13
+ Network string
14
+
15
+ // Own network address
16
+ Address string
17
+ ResolvedAddress string
18
+
19
+ // Connection
20
+ conn *net.Conn
21
+
22
+ // next packets + close control channels
23
+ Input chan *Packet
24
+ Output chan *Packet
25
+ Closed chan bool
26
+ Errors chan error
27
+}
28
+
29
+func NewUDPInterface(net, addr string) (*Interface, error) {
30
+ raddr, err := net.ResolveUDPAddr(net, addr)
31
+ if err != nil {
32
+ return nil, err
33
+ }
34
+
35
+ conn, err := net.ListenUDP(net, addr)
36
+ if err != nil {
37
+ return nil, err
38
+ }
39
+
40
+ i := &Interface{
41
+ Network: net,
42
+ Address: addr,
43
+ ResolvedAddress: raddr,
44
+ conn: conn,
45
+ }
46
+
47
+ go i.processInput()
48
+ go i.processOutput()
49
+ return i, nil
50
+}
51
+
52
+func (i *Interface) processOutput() {
53
+ for {
54
+ select {
55
+ case <-i.Closed:
56
+ break;
57
+
58
+ case buffer := <-i.Output:
59
+ i.conn.Write([]byte(buffer))
60
+ }
61
+ }
62
+}
63
+
64
+func (i *Interface) processUDPInput() {
65
+ for {
66
+ select {
67
+ case <- i.Closed:
68
+ break;
69
+
70
+ }
71
+ }
72
+}
73
+
74
+func (i *Interface) Read(buffer []byte) bool {
75
+ n, err := i.Conn.Read(buffer)
76
+ if err != nil {
77
+ i.Errors <- err
78
+ i.Close()
79
+ return false
80
+ }
81
+ return true
82
+}
83
+
84
+func (i *Interface) Close() {
85
+ // closing net connection
86
+ err := i.conn.Close()
87
+ if err != nil {
88
+ i.Errors <- err
89
+ }
90
+
91
+ // closing channels
92
+ close(i.Input)
93
+ close(i.Output)
94
+ close(i.Closed)
95
+ close(i.Errors)
96
+}
netmux/netmux.go
new
+51
@@ -0,0 +1,51 @@
1
+package netmux
2
+
3
+import (
4
+ "net"
5
+)
6
+
7
+// The netmux module provides a "network multiplexer".
8
+// The core idea is to have the client be able to connect to
9
+// many different networks (potentially over different transports)
10
+// and multiplex everything over one interface.
11
+
12
+type Netmux struct {
13
+ // the list of NetMux interfaces
14
+ Interfaces []*Interface
15
+
16
+ // The channels to send/recv from
17
+ Incoming <-chan *Packet
18
+ Outgoing chan<- *Packet
19
+
20
+ // internally managed other side of channels
21
+ incomingSrc chan<- *Packet
22
+ outgoingSrc <-chan *Packet
23
+}
24
+
25
+
26
+// Warning: will probably change to adopt multiaddr format
27
+type Packet {
28
+ // the network addresses to send to
29
+ // e.g. tcp4://127.0.0.1:12345
30
+ NetAddrTo string
31
+
32
+ // the network addresses to recv from
33
+ // e.g. tcp4://127.0.0.1:12345
34
+ // may be left blank to select one automatically.
35
+ NetAddrFrom string
36
+
37
+ // the data to send.
38
+ Data []byte
39
+}
40
+
41
+func NewNetmux() *Netmux {
42
+ n := &Netmux{}
43
+
44
+ // setup channels
45
+ och := make(chan *Packet)
46
+ ich := make(chan *Packet)
47
+ n.Incoming, n.incomingSrc := ich, ich
48
+ n.Outgoing, n.outgoingSrc := och, och
49
+
50
+ return n
51
+}
object/object.go
path/path.go
peer/peer.go
routing/routing.go
new
+4
@@ -0,0 +1,4 @@
1
+package routing
2
+
3
+
4
+TODO SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-routing/index.js