whole project go fmt
Juan Batiz-Benet committed
Jul 29, 2014 at 17:55 UTC
74d26449c98267cb3c06f56ad2752d7d89c5202b
5 files changed
+49
-53
bitswap/bitswap.go
+11
-9
@@ -1,24 +1,26 @@
1
package bitswap
2
3
import (
4
- "time"
5
- mh "github.com/jbenet/go-multihash"
6
- blocks "github.com/jbenet/go-ipfs/blocks"
7
- u "github.com/jbenet/go-ipfs/util"
4
+ blocks "github.com/jbenet/go-ipfs/blocks"
5
+ peer "github.com/jbenet/go-ipfs/peer"
6
+ u "github.com/jbenet/go-ipfs/util"
7
+ mh "github.com/jbenet/go-multihash"
8
+ "time"
9
)
10
11
// aliases
12
13
type Ledger struct {
13
- Owner mh.Multihash
14
- Partner mh.Multihash
14
+ Owner mh.Multihash
15
+ Partner mh.Multihash
16
BytesSent uint64
17
BytesRecv uint64
18
Timestamp *time.Time
19
}
20
21
type BitSwap struct {
21
- Ledgers map[u.Key]*Ledger // key is peer.ID
22
- HaveList map[u.Key]*blocks.Block // key is multihash
23
- WantList []*mh.Multihash
22
+ Ledgers map[u.Key]*Ledger // key is peer.ID
23
+ HaveList map[u.Key]*blocks.Block // key is multihash
24
+ WantList []*mh.Multihash
25
+ // todo
26
}
routing/dht/dht.go
+2
-3
@@ -7,7 +7,6 @@ import (
7
8
// TODO. SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-dht/index.js
9
10
-
10
// IpfsDHT is an implementation of Kademlia with Coral and S/Kademlia modifications.
11
// It is used to implement the base IpfsRouting module.
12
type IpfsDHT struct {
@@ -15,7 +14,7 @@ type IpfsDHT struct {
14
15
network *swarm.Swarm
16
18
- listeners map[uint64]chan swarm.Message
17
+ listeners map[uint64]chan swarm.Message
18
listenLock sync.RWMutex
19
}
20
@@ -35,7 +34,7 @@ func (dht *IpfsDHT) handleMessages() {
34
ch <- mes
35
}
36
38
- //case closeChan: or something
37
+ //case closeChan: or something
38
}
39
}
40
}
routing/dht/routing.go
+14
-17
@@ -1,19 +1,18 @@
1
package dht
2
3
import (
4
- "time"
5
- peer "github.com/jbenet/go-ipfs/peer"
6
- u "github.com/jbenet/go-ipfs/util"
7
- swarm "github.com/jbenet/go-ipfs/swarm"
4
+ peer "github.com/jbenet/go-ipfs/peer"
5
+ swarm "github.com/jbenet/go-ipfs/swarm"
6
+ u "github.com/jbenet/go-ipfs/util"
7
+ "time"
8
)
9
10
-
10
// This file implements the Routing interface for the IpfsDHT struct.
11
12
// Basic Put/Get
13
14
// PutValue adds value corresponding to given Key.
16
-func (s *IpfsDHT) PutValue(key u.Key, value []byte) (error) {
15
+func (s *IpfsDHT) PutValue(key u.Key, value []byte) error {
16
var p *peer.Peer
17
p = s.routes.NearestNode(key)
18
@@ -48,35 +47,33 @@ func (s *IpfsDHT) GetValue(key u.Key, timeout time.Duration) ([]byte, error) {
47
// Wait for either the response or a timeout
48
timeup := time.After(timeout)
49
select {
51
- case <-timeup:
52
- // TODO: unregister listener
53
- return nil, timeoutError
54
- case resp := <-response_chan:
55
- return resp.Data, nil
50
+ case <-timeup:
51
+ // TODO: unregister listener
52
+ return nil, timeoutError
53
+ case resp := <-response_chan:
54
+ return resp.Data, nil
55
}
56
57
// Should never be hit
58
return nil, nil
59
}
60
62
-
61
// Value provider layer of indirection.
62
// This is what DSHTs (Coral and MainlineDHT) do to store large values in a DHT.
63
64
// Announce that this node can provide value for given key
67
-func (s *IpfsDHT) Provide(key u.Key) (error) {
68
- return u.ErrNotImplemented
65
+func (s *IpfsDHT) Provide(key u.Key) error {
66
+ return u.ErrNotImplemented
67
}
68
69
// FindProviders searches for peers who can provide the value for given key.
70
func (s *IpfsDHT) FindProviders(key u.Key, timeout time.Duration) (*peer.Peer, error) {
73
- return nil, u.ErrNotImplemented
71
+ return nil, u.ErrNotImplemented
72
}
73
76
-
74
// Find specific Peer
75
76
// FindPeer searches for a peer with given ID.
77
func (s *IpfsDHT) FindPeer(id peer.ID, timeout time.Duration) (*peer.Peer, error) {
81
- return nil, u.ErrNotImplemented
78
+ return nil, u.ErrNotImplemented
79
}
routing/routing.go
+17
-19
@@ -1,36 +1,34 @@
1
package routing
2
3
import (
4
- "time"
5
- peer "github.com/jbenet/go-ipfs/peer"
6
- u "github.com/jbenet/go-ipfs/util"
4
+ peer "github.com/jbenet/go-ipfs/peer"
5
+ u "github.com/jbenet/go-ipfs/util"
6
+ "time"
7
)
8
9
// IpfsRouting is the routing module interface
10
// It is implemented by things like DHTs, etc.
11
type IpfsRouting interface {
12
13
- // Basic Put/Get
13
+ // Basic Put/Get
14
15
- // PutValue adds value corresponding to given Key.
16
- PutValue(key u.Key, value []byte) (error)
15
+ // PutValue adds value corresponding to given Key.
16
+ PutValue(key u.Key, value []byte) error
17
18
- // GetValue searches for the value corresponding to given Key.
19
- GetValue(key u.Key, timeout time.Duration) ([]byte, error)
18
+ // GetValue searches for the value corresponding to given Key.
19
+ GetValue(key u.Key, timeout time.Duration) ([]byte, error)
20
21
+ // Value provider layer of indirection.
22
+ // This is what DSHTs (Coral and MainlineDHT) do to store large values in a DHT.
23
22
- // Value provider layer of indirection.
23
- // This is what DSHTs (Coral and MainlineDHT) do to store large values in a DHT.
24
+ // Announce that this node can provide value for given key
25
+ Provide(key u.Key) error
26
25
- // Announce that this node can provide value for given key
26
- Provide(key u.Key) (error)
27
+ // FindProviders searches for peers who can provide the value for given key.
28
+ FindProviders(key u.Key, timeout time.Duration) (*peer.Peer, error)
29
28
- // FindProviders searches for peers who can provide the value for given key.
29
- FindProviders(key u.Key, timeout time.Duration) (*peer.Peer, error)
30
+ // Find specific Peer
31
31
-
32
- // Find specific Peer
33
-
34
- // FindPeer searches for a peer with given ID.
35
- FindPeer(id peer.ID, timeout time.Duration) (*peer.Peer, error)
32
+ // FindPeer searches for a peer with given ID.
33
+ FindPeer(id peer.ID, timeout time.Duration) (*peer.Peer, error)
34
}
swarm/swarm.go
+5
-5
@@ -3,10 +3,10 @@ package swarm
3
import (
4
"fmt"
5
peer "github.com/jbenet/go-ipfs/peer"
6
- ma "github.com/jbenet/go-multiaddr"
6
u "github.com/jbenet/go-ipfs/util"
8
- "sync"
7
+ ma "github.com/jbenet/go-multiaddr"
8
"net"
9
+ "sync"
10
)
11
12
// Message represents a packet of information sent to or received from a
@@ -46,7 +46,7 @@ type Swarm struct {
46
conns ConnMap
47
connsLock sync.RWMutex
48
49
- local *peer.Peer
49
+ local *peer.Peer
50
}
51
52
// NewSwarm constructs a Swarm, with a Chan.
@@ -62,7 +62,7 @@ func NewSwarm(local *peer.Peer) *Swarm {
62
63
// Open listeners for each network the swarm should listen on
64
func (s *Swarm) Listen() {
65
- for _,addr := range s.local.Addresses {
65
+ for _, addr := range s.local.Addresses {
66
err := s.connListen(addr)
67
if err != nil {
68
u.PErr("Failed to listen on: %s [%s]", addr, err)
@@ -85,7 +85,7 @@ func (s *Swarm) connListen(maddr *ma.Multiaddr) error {
85
// Accept and handle new connections on this listener until it errors
86
go func() {
87
for {
88
- nconn,err := list.Accept()
88
+ nconn, err := list.Accept()
89
if err != nil {
90
u.PErr("Failed to accept connection: %s - %s", netstr, addr)
91
return