1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-12 07:55:07 +08:00
Files
kubo/netmux/netmux.go
Juan Batiz-Benet 3b570d3f82 skeleton.
2014-06-26 01:14:26 -07:00

52 lines
1.1 KiB
Go

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 channels to send/recv from
Incoming <-chan *Packet
Outgoing 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
}
func NewNetmux() *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
return n
}