gofmt
Carlos Cobo committed
Jul 24, 2014 at 14:31 UTC
4b06adf7fcf5fcd66df30bbedd60236a9de81eeb
3 files changed
+96
-96
bitswap/bitswap.go
+6
-6
@@ -1,18 +1,18 @@
1
package bitswap
2
3
import (
4
- "github.com/jbenet/go-ipfs/blocks"
5
- "github.com/jbenet/go-multihash"
4
+ "github.com/jbenet/go-ipfs/blocks"
5
+ "github.com/jbenet/go-multihash"
6
)
7
8
// aliases
9
10
type Ledger struct {
11
- // todo
11
+ // todo
12
}
13
14
type BitSwap struct {
15
- Ledgers map[string]*Ledger
16
- HaveList map[string]*blocks.Block
17
- WantList []*multihash.Multihash
15
+ Ledgers map[string]*Ledger
16
+ HaveList map[string]*blocks.Block
17
+ WantList []*multihash.Multihash
18
}
netmux/interface.go
+66
-66
@@ -1,7 +1,7 @@
1
package netmux
2
3
import (
4
- "net"
4
+ "net"
5
)
6
7
// An interface is the module connecting netmux
@@ -9,88 +9,88 @@ import (
9
// It keeps the relevant connections open.
10
type Interface struct {
11
12
- // Interface network (e.g. udp4, tcp6)
13
- Network string
12
+ // Interface network (e.g. udp4, tcp6)
13
+ Network string
14
15
- // Own network address
16
- Address string
17
- ResolvedAddress *net.UDPAddr
15
+ // Own network address
16
+ Address string
17
+ ResolvedAddress *net.UDPAddr
18
19
- // Connection
20
- conn net.Conn
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
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(network, addr string) (*Interface, error) {
30
- raddr, err := net.ResolveUDPAddr(network, addr)
31
- if err != nil {
32
- return nil, err
33
- }
34
-
35
- conn, err := net.ListenUDP(network, raddr)
36
- if err != nil {
37
- return nil, err
38
- }
39
-
40
- i := &Interface{
41
- Network: network,
42
- Address: addr,
43
- ResolvedAddress: raddr,
44
- conn: conn,
45
- }
46
-
47
- go i.processUDPInput()
48
- go i.processOutput()
49
- return i, nil
30
+ raddr, err := net.ResolveUDPAddr(network, addr)
31
+ if err != nil {
32
+ return nil, err
33
+ }
34
+
35
+ conn, err := net.ListenUDP(network, raddr)
36
+ if err != nil {
37
+ return nil, err
38
+ }
39
+
40
+ i := &Interface{
41
+ Network: network,
42
+ Address: addr,
43
+ ResolvedAddress: raddr,
44
+ conn: conn,
45
+ }
46
+
47
+ go i.processUDPInput()
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.Data))
60
- }
61
- }
53
+ for {
54
+ select {
55
+ case <-i.Closed:
56
+ break
57
+
58
+ case buffer := <-i.Output:
59
+ i.conn.Write([]byte(buffer.Data))
60
+ }
61
+ }
62
}
63
64
func (i *Interface) processUDPInput() {
65
- for {
66
- select {
67
- case <-i.Closed:
68
- break
65
+ for {
66
+ select {
67
+ case <-i.Closed:
68
+ break
69
70
- }
71
- }
70
+ }
71
+ }
72
}
73
74
func (i *Interface) Read(buffer []byte) bool {
75
- _, err := i.conn.Read(buffer)
76
- if err != nil {
77
- i.Errors <- err
78
- i.Close()
79
- return false
80
- }
81
- return true
75
+ _, 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)
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
+24
-24
@@ -6,41 +6,41 @@ package netmux
6
// and multiplex everything over one interface.
7
8
type Netmux struct {
9
- // the list of NetMux interfaces
10
- Interfaces []*Interface
9
+ // the list of NetMux interfaces
10
+ Interfaces []*Interface
11
12
- // The channels to send/recv from
13
- Incoming <-chan *Packet
14
- Outgoing chan<- *Packet
12
+ // The channels to send/recv from
13
+ Incoming <-chan *Packet
14
+ Outgoing chan<- *Packet
15
16
- // internally managed other side of channels
17
- incomingSrc chan<- *Packet
18
- outgoingSrc <-chan *Packet
16
+ // internally managed other side of channels
17
+ incomingSrc chan<- *Packet
18
+ outgoingSrc <-chan *Packet
19
}
20
21
// Warning: will probably change to adopt multiaddr format
22
type Packet struct {
23
- // the network addresses to send to
24
- // e.g. tcp4://127.0.0.1:12345
25
- NetAddrTo string
23
+ // the network addresses to send to
24
+ // e.g. tcp4://127.0.0.1:12345
25
+ NetAddrTo string
26
27
- // the network addresses to recv from
28
- // e.g. tcp4://127.0.0.1:12345
29
- // may be left blank to select one automatically.
30
- NetAddrFrom string
27
+ // the network addresses to recv from
28
+ // e.g. tcp4://127.0.0.1:12345
29
+ // may be left blank to select one automatically.
30
+ NetAddrFrom string
31
32
- // the data to send.
33
- Data []byte
32
+ // the data to send.
33
+ Data []byte
34
}
35
36
func NewNetmux() *Netmux {
37
- n := &Netmux{}
37
+ n := &Netmux{}
38
39
- // setup channels
40
- och := make(chan *Packet)
41
- ich := make(chan *Packet)
42
- n.Incoming, n.incomingSrc = ich, ich
43
- n.Outgoing, n.outgoingSrc = och, och
39
+ // setup channels
40
+ och := make(chan *Packet)
41
+ ich := make(chan *Packet)
42
+ n.Incoming, n.incomingSrc = ich, ich
43
+ n.Outgoing, n.outgoingSrc = och, och
44
45
- return n
45
+ return n
46
}