mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 09:59:13 +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
|
package bitswap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
"github.com/jbenet/go-ipfs/blocks"
|
||||||
|
"github.com/jbenet/go-multihash"
|
||||||
)
|
)
|
||||||
|
|
||||||
// aliases
|
// aliases
|
||||||
@ -11,7 +12,7 @@ type Ledger struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BitSwap struct {
|
type BitSwap struct {
|
||||||
Ledgers map[peer.ID]*Ledger
|
Ledgers map[string]*Ledger
|
||||||
HaveList map[multihash.Multihash]*block.Block
|
HaveList map[string]*blocks.Block
|
||||||
WantList []*multihash.Multihash
|
WantList []*multihash.Multihash
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,10 @@ type Interface struct {
|
|||||||
|
|
||||||
// Own network address
|
// Own network address
|
||||||
Address string
|
Address string
|
||||||
ResolvedAddress string
|
ResolvedAddress *net.UDPAddr
|
||||||
|
|
||||||
// Connection
|
// Connection
|
||||||
conn *net.Conn
|
conn net.Conn
|
||||||
|
|
||||||
// next packets + close control channels
|
// next packets + close control channels
|
||||||
Input chan *Packet
|
Input chan *Packet
|
||||||
@ -26,25 +26,25 @@ type Interface struct {
|
|||||||
Errors chan error
|
Errors chan error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUDPInterface(net, addr string) (*Interface, error) {
|
func NewUDPInterface(network, addr string) (*Interface, error) {
|
||||||
raddr, err := net.ResolveUDPAddr(net, addr)
|
raddr, err := net.ResolveUDPAddr(network, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := net.ListenUDP(net, addr)
|
conn, err := net.ListenUDP(network, raddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
i := &Interface{
|
i := &Interface{
|
||||||
Network: net,
|
Network: network,
|
||||||
Address: addr,
|
Address: addr,
|
||||||
ResolvedAddress: raddr,
|
ResolvedAddress: raddr,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
}
|
}
|
||||||
|
|
||||||
go i.processInput()
|
go i.processUDPInput()
|
||||||
go i.processOutput()
|
go i.processOutput()
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
@ -53,10 +53,10 @@ func (i *Interface) processOutput() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-i.Closed:
|
case <-i.Closed:
|
||||||
break;
|
break
|
||||||
|
|
||||||
case buffer := <-i.Output:
|
case buffer := <-i.Output:
|
||||||
i.conn.Write([]byte(buffer))
|
i.conn.Write([]byte(buffer.Data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,14 +65,14 @@ func (i *Interface) processUDPInput() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-i.Closed:
|
case <-i.Closed:
|
||||||
break;
|
break
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Interface) Read(buffer []byte) bool {
|
func (i *Interface) Read(buffer []byte) bool {
|
||||||
n, err := i.Conn.Read(buffer)
|
_, err := i.conn.Read(buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
i.Errors <- err
|
i.Errors <- err
|
||||||
i.Close()
|
i.Close()
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package netmux
|
package netmux
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
)
|
|
||||||
|
|
||||||
// The netmux module provides a "network multiplexer".
|
// The netmux module provides a "network multiplexer".
|
||||||
// The core idea is to have the client be able to connect to
|
// The core idea is to have the client be able to connect to
|
||||||
// many different networks (potentially over different transports)
|
// many different networks (potentially over different transports)
|
||||||
@ -22,9 +18,8 @@ type Netmux struct {
|
|||||||
outgoingSrc <-chan *Packet
|
outgoingSrc <-chan *Packet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Warning: will probably change to adopt multiaddr format
|
// Warning: will probably change to adopt multiaddr format
|
||||||
type Packet {
|
type Packet struct {
|
||||||
// the network addresses to send to
|
// the network addresses to send to
|
||||||
// e.g. tcp4://127.0.0.1:12345
|
// e.g. tcp4://127.0.0.1:12345
|
||||||
NetAddrTo string
|
NetAddrTo string
|
||||||
@ -44,8 +39,8 @@ func NewNetmux() *Netmux {
|
|||||||
// setup channels
|
// setup channels
|
||||||
och := make(chan *Packet)
|
och := make(chan *Packet)
|
||||||
ich := make(chan *Packet)
|
ich := make(chan *Packet)
|
||||||
n.Incoming, n.incomingSrc := ich, ich
|
n.Incoming, n.incomingSrc = ich, ich
|
||||||
n.Outgoing, n.outgoingSrc := och, och
|
n.Outgoing, n.outgoingSrc = och, och
|
||||||
|
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user