mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-27 16:07:42 +08:00
Merge pull request #8 from toqueteos/master
Fix #1 build errors + gofmt
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ type Interface struct {
|
||||
|
||||
// Own network address
|
||||
Address string
|
||||
ResolvedAddress string
|
||||
ResolvedAddress *net.UDPAddr
|
||||
|
||||
// Connection
|
||||
conn *net.Conn
|
||||
conn net.Conn
|
||||
|
||||
// next packets + close control channels
|
||||
Input chan *Packet
|
||||
@ -26,25 +26,25 @@ type Interface struct {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,14 +65,14 @@ func (i *Interface) processUDPInput() {
|
||||
for {
|
||||
select {
|
||||
case <-i.Closed:
|
||||
break;
|
||||
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()
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user