From 7d6a58308b977273ab03ad0e0235cddf9e0fcb58 Mon Sep 17 00:00:00 2001 From: Carlos Cobo Date: Thu, 24 Jul 2014 14:30:23 +0200 Subject: [PATCH 1/2] Fix #1 build errors. --- bitswap/bitswap.go | 7 ++++--- netmux/interface.go | 28 ++++++++++++++-------------- netmux/netmux.go | 11 +++-------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/bitswap/bitswap.go b/bitswap/bitswap.go index 44e0c393c..c58750920 100644 --- a/bitswap/bitswap.go +++ b/bitswap/bitswap.go @@ -1,7 +1,8 @@ package bitswap import ( - peer "github.com/jbenet/go-ipfs/peer" + "github.com/jbenet/go-ipfs/blocks" + "github.com/jbenet/go-multihash" ) // aliases @@ -11,7 +12,7 @@ type Ledger struct { } type BitSwap struct { - Ledgers map[peer.ID]*Ledger - HaveList map[multihash.Multihash]*block.Block + Ledgers map[string]*Ledger + HaveList map[string]*blocks.Block WantList []*multihash.Multihash } diff --git a/netmux/interface.go b/netmux/interface.go index 68819a930..af49c6d0c 100644 --- a/netmux/interface.go +++ b/netmux/interface.go @@ -13,38 +13,38 @@ type Interface struct { Network string // Own network address - Address string - ResolvedAddress string + Address string + ResolvedAddress *net.UDPAddr // Connection - conn *net.Conn + conn net.Conn // next packets + close control channels - Input chan *Packet + Input chan *Packet Output chan *Packet Closed chan bool Errors chan error } -func NewUDPInterface(net, addr string) (*Interface, error) { - raddr, err := net.ResolveUDPAddr(net, addr) +func NewUDPInterface(network, addr string) (*Interface, error) { + raddr, err := net.ResolveUDPAddr(network, addr) if err != nil { return nil, err } - conn, err := net.ListenUDP(net, addr) + conn, err := net.ListenUDP(network, raddr) if err != nil { return nil, err } i := &Interface{ - Network: net, + Network: network, Address: addr, ResolvedAddress: raddr, conn: conn, } - go i.processInput() + go i.processUDPInput() go i.processOutput() return i, nil } @@ -53,10 +53,10 @@ func (i *Interface) processOutput() { for { select { case <-i.Closed: - break; + break case buffer := <-i.Output: - i.conn.Write([]byte(buffer)) + i.conn.Write([]byte(buffer.Data)) } } } @@ -64,15 +64,15 @@ func (i *Interface) processOutput() { func (i *Interface) processUDPInput() { for { select { - case <- i.Closed: - break; + case <-i.Closed: + break } } } func (i *Interface) Read(buffer []byte) bool { - n, err := i.Conn.Read(buffer) + _, err := i.conn.Read(buffer) if err != nil { i.Errors <- err i.Close() diff --git a/netmux/netmux.go b/netmux/netmux.go index eb71e2190..3ef3654b6 100644 --- a/netmux/netmux.go +++ b/netmux/netmux.go @@ -1,9 +1,5 @@ package netmux -import ( - "net" -) - // The netmux module provides a "network multiplexer". // The core idea is to have the client be able to connect to // many different networks (potentially over different transports) @@ -22,9 +18,8 @@ type Netmux struct { outgoingSrc <-chan *Packet } - // Warning: will probably change to adopt multiaddr format -type Packet { +type Packet struct { // the network addresses to send to // e.g. tcp4://127.0.0.1:12345 NetAddrTo string @@ -44,8 +39,8 @@ func NewNetmux() *Netmux { // setup channels och := make(chan *Packet) ich := make(chan *Packet) - n.Incoming, n.incomingSrc := ich, ich - n.Outgoing, n.outgoingSrc := och, och + n.Incoming, n.incomingSrc = ich, ich + n.Outgoing, n.outgoingSrc = och, och return n } From 4b06adf7fcf5fcd66df30bbedd60236a9de81eeb Mon Sep 17 00:00:00 2001 From: Carlos Cobo Date: Thu, 24 Jul 2014 14:31:41 +0200 Subject: [PATCH 2/2] gofmt --- bitswap/bitswap.go | 12 ++--- netmux/interface.go | 122 ++++++++++++++++++++++---------------------- netmux/netmux.go | 48 ++++++++--------- 3 files changed, 91 insertions(+), 91 deletions(-) diff --git a/bitswap/bitswap.go b/bitswap/bitswap.go index c58750920..f457d47dc 100644 --- a/bitswap/bitswap.go +++ b/bitswap/bitswap.go @@ -1,18 +1,18 @@ package bitswap import ( - "github.com/jbenet/go-ipfs/blocks" - "github.com/jbenet/go-multihash" + "github.com/jbenet/go-ipfs/blocks" + "github.com/jbenet/go-multihash" ) // aliases type Ledger struct { - // todo + // todo } type BitSwap struct { - Ledgers map[string]*Ledger - HaveList map[string]*blocks.Block - WantList []*multihash.Multihash + Ledgers map[string]*Ledger + HaveList map[string]*blocks.Block + WantList []*multihash.Multihash } diff --git a/netmux/interface.go b/netmux/interface.go index af49c6d0c..a1aa9b960 100644 --- a/netmux/interface.go +++ b/netmux/interface.go @@ -1,7 +1,7 @@ package netmux import ( - "net" + "net" ) // An interface is the module connecting netmux @@ -9,88 +9,88 @@ import ( // It keeps the relevant connections open. type Interface struct { - // Interface network (e.g. udp4, tcp6) - Network string + // Interface network (e.g. udp4, tcp6) + Network string - // Own network address - Address string - ResolvedAddress *net.UDPAddr + // Own network address + Address string + ResolvedAddress *net.UDPAddr - // Connection - conn net.Conn + // Connection + conn net.Conn - // next packets + close control channels - Input chan *Packet - Output chan *Packet - Closed chan bool - Errors chan error + // next packets + close control channels + Input chan *Packet + Output chan *Packet + Closed chan bool + Errors chan error } func NewUDPInterface(network, addr string) (*Interface, error) { - raddr, err := net.ResolveUDPAddr(network, addr) - if err != nil { - return nil, err - } + raddr, err := net.ResolveUDPAddr(network, addr) + if err != nil { + return nil, err + } - conn, err := net.ListenUDP(network, raddr) - if err != nil { - return nil, err - } + conn, err := net.ListenUDP(network, raddr) + if err != nil { + return nil, err + } - i := &Interface{ - Network: network, - Address: addr, - ResolvedAddress: raddr, - conn: conn, - } + i := &Interface{ + Network: network, + Address: addr, + ResolvedAddress: raddr, + conn: conn, + } - go i.processUDPInput() - go i.processOutput() - return i, nil + go i.processUDPInput() + go i.processOutput() + return i, nil } func (i *Interface) processOutput() { - for { - select { - case <-i.Closed: - break + for { + select { + case <-i.Closed: + break - case buffer := <-i.Output: - i.conn.Write([]byte(buffer.Data)) - } - } + case buffer := <-i.Output: + i.conn.Write([]byte(buffer.Data)) + } + } } func (i *Interface) processUDPInput() { - for { - select { - case <-i.Closed: - break + for { + select { + case <-i.Closed: + break - } - } + } + } } func (i *Interface) Read(buffer []byte) bool { - _, err := i.conn.Read(buffer) - if err != nil { - i.Errors <- err - i.Close() - return false - } - return true + _, err := i.conn.Read(buffer) + if err != nil { + i.Errors <- err + i.Close() + return false + } + return true } func (i *Interface) Close() { - // closing net connection - err := i.conn.Close() - if err != nil { - i.Errors <- err - } + // closing net connection + err := i.conn.Close() + if err != nil { + i.Errors <- err + } - // closing channels - close(i.Input) - close(i.Output) - close(i.Closed) - close(i.Errors) + // closing channels + close(i.Input) + close(i.Output) + close(i.Closed) + close(i.Errors) } diff --git a/netmux/netmux.go b/netmux/netmux.go index 3ef3654b6..d5a98a5f4 100644 --- a/netmux/netmux.go +++ b/netmux/netmux.go @@ -6,41 +6,41 @@ package netmux // and multiplex everything over one interface. type Netmux struct { - // the list of NetMux interfaces - Interfaces []*Interface + // the list of NetMux interfaces + Interfaces []*Interface - // The channels to send/recv from - Incoming <-chan *Packet - Outgoing chan<- *Packet + // The channels to send/recv from + Incoming <-chan *Packet + Outgoing chan<- *Packet - // internally managed other side of channels - incomingSrc chan<- *Packet - outgoingSrc <-chan *Packet + // internally managed other side of channels + incomingSrc chan<- *Packet + outgoingSrc <-chan *Packet } // Warning: will probably change to adopt multiaddr format type Packet struct { - // the network addresses to send to - // e.g. tcp4://127.0.0.1:12345 - NetAddrTo string + // the network addresses to send to + // e.g. tcp4://127.0.0.1:12345 + NetAddrTo string - // the network addresses to recv from - // e.g. tcp4://127.0.0.1:12345 - // may be left blank to select one automatically. - NetAddrFrom string + // the network addresses to recv from + // e.g. tcp4://127.0.0.1:12345 + // may be left blank to select one automatically. + NetAddrFrom string - // the data to send. - Data []byte + // the data to send. + Data []byte } func NewNetmux() *Netmux { - n := &Netmux{} + n := &Netmux{} - // setup channels - och := make(chan *Packet) - ich := make(chan *Packet) - n.Incoming, n.incomingSrc = ich, ich - n.Outgoing, n.outgoingSrc = och, och + // setup channels + och := make(chan *Packet) + ich := make(chan *Packet) + n.Incoming, n.incomingSrc = ich, ich + n.Outgoing, n.outgoingSrc = och, och - return n + return n }