Skip to content

Commit

Permalink
Merge pull request #8 from toqueteos/master
Browse files Browse the repository at this point in the history
Fix #1 build errors + gofmt
  • Loading branch information
jbenet committed Jul 24, 2014
2 parents 1fb29a2 + 4b06adf commit c814dd0
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 104 deletions.
11 changes: 6 additions & 5 deletions bitswap/bitswap.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package bitswap

import (
peer "github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/blocks"
"github.com/jbenet/go-multihash"
)

// aliases

type Ledger struct {
// todo
// todo
}

type BitSwap struct {
Ledgers map[peer.ID]*Ledger
HaveList map[multihash.Multihash]*block.Block
WantList []*multihash.Multihash
Ledgers map[string]*Ledger
HaveList map[string]*blocks.Block
WantList []*multihash.Multihash
}
134 changes: 67 additions & 67 deletions netmux/interface.go
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
package netmux

import (
"net"
"net"
)

// An interface is the module connecting netmux
// to various networks (tcp, udp, webrtc, etc).
// 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 string
// 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(net, addr string) (*Interface, error) {
raddr, err := net.ResolveUDPAddr(net, addr)
if err != nil {
return nil, err
}

conn, err := net.ListenUDP(net, addr)
if err != nil {
return nil, err
}

i := &Interface{
Network: net,
Address: addr,
ResolvedAddress: raddr,
conn: conn,
}

go i.processInput()
go i.processOutput()
return i, nil
func NewUDPInterface(network, addr string) (*Interface, error) {
raddr, err := net.ResolveUDPAddr(network, addr)
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,
}

go i.processUDPInput()
go i.processOutput()
return i, nil
}

func (i *Interface) processOutput() {
for {
select {
case <-i.Closed:
break;

case buffer := <-i.Output:
i.conn.Write([]byte(buffer))
}
}
for {
select {
case <-i.Closed:
break

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 {
n, 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 channels
close(i.Input)
close(i.Output)
close(i.Closed)
close(i.Errors)
// 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)
}
59 changes: 27 additions & 32 deletions netmux/netmux.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@
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)
// 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 {
// 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 data to send.
Data []byte
type Packet struct {
// 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 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
}

0 comments on commit c814dd0

Please sign in to comment.