-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 *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 | ||
} | ||
|
||
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 | ||
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.Data)) | ||
} | ||
} | ||
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 { | ||
_, 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters