Documentation ¶
Index ¶
- Constants
- Variables
- type Address
- type Bucket
- type BucketList
- type BucketListTask
- type Connector
- type Endpoint
- type FindNodeMsg
- type FindNodeRespMsg
- type HandlerList
- type LocalAddress
- type LocalConnector
- func (c *LocalConnector) Epoch(epoch int)
- func (c *LocalConnector) Learn(addr *Address, endp net.Addr) error
- func (c *LocalConnector) Listen(ctx context.Context, ch chan Message)
- func (c *LocalConnector) NewAddress(endp string) (net.Addr, error)
- func (c *LocalConnector) Resolve(addr *Address) net.Addr
- func (c *LocalConnector) Sample(num int, skip *Address) []*Address
- func (c *LocalConnector) Send(ctx context.Context, dst net.Addr, pkt *Packet) error
- type LocalTransport
- type LookupService
- func (s *LookupService) Lookup(ctx context.Context, addr *Address, resolver Query, timeout time.Duration) (res interface{}, err error)
- func (s *LookupService) LookupNode(ctx context.Context, addr *Address, timeout time.Duration) (entry *Endpoint, err error)
- func (s *LookupService) Name() string
- func (s *LookupService) NewMessage(mt int) Message
- func (s *LookupService) Request(ctx context.Context, rcv, addr *Address, timeout time.Duration) (res []*Endpoint, err error)
- func (s *LookupService) Respond(ctx context.Context, m Message) (bool, error)
- type Message
- type MessageFactory
- type MessageHandler
- type MsgHeader
- type NewMessage
- type Node
- func (n *Node) AddService(s Service) bool
- func (n *Node) Address() *Address
- func (n *Node) Closest(num int) []*Address
- func (n *Node) Connect(c Connector) error
- func (n *Node) Handle() chan Message
- func (n *Node) Learn(addr *Address, endp string) error
- func (n *Node) LookupService() *LookupService
- func (n *Node) NewNetworkAddr(endp string) (net.Addr, error)
- func (n *Node) NextID() uint64
- func (n *Node) Pack(msg Message) ([]byte, error)
- func (n *Node) PingService() *PingService
- func (n *Node) RelayService() *RelayService
- func (n *Node) RelayedMessage(msg Message, peers []*Address) (Message, error)
- func (n *Node) Resolve(addr *Address) net.Addr
- func (n *Node) Run(ctx context.Context)
- func (n *Node) Sample(num int, skip *Address) []*Address
- func (n *Node) Send(ctx context.Context, msg Message) (err error)
- func (n *Node) SendRaw(ctx context.Context, dst net.Addr, pkt *Packet) error
- func (n *Node) Service(name string) Service
- func (n *Node) Unpack(buf []byte, size int) (msg Message, err error)
- func (n *Node) Unwrap(pkt *Packet) (msg Message, err error)
- func (n *Node) Wrap(msg Message) (pkt *Packet, err error)
- type Packet
- type PingMsg
- type PingService
- type PongMsg
- type Query
- type RelayMsg
- type RelayService
- type Service
- type ServiceImpl
- func (s *ServiceImpl) Listen(ctx context.Context, msg Message) (bool, error)
- func (s *ServiceImpl) MessageFactory(mt int) Message
- func (s *ServiceImpl) Node() *Node
- func (s *ServiceImpl) Respond(ctx context.Context, msg Message) (bool, error)
- func (s *ServiceImpl) Send(ctx context.Context, msg Message) error
- func (s *ServiceImpl) Task(ctx context.Context, m Message, f *TaskHandler) (err error)
- type ServiceList
- func (sl *ServiceList) Add(s Service) bool
- func (sl *ServiceList) Get(name string) Service
- func (sl *ServiceList) Listen(ctx context.Context, msg Message) (bool, error)
- func (sl *ServiceList) MessageFactory(buf []byte) (Message, error)
- func (sl *ServiceList) Respond(ctx context.Context, msg Message) (bool, error)
- type String
- type TaskHandler
- type TorAddress
- type TorConnection
- type TorConnector
- func (c *TorConnector) Epoch(epoch int)
- func (c *TorConnector) Learn(addr *Address, endp net.Addr) error
- func (c *TorConnector) Listen(ctx context.Context, ch chan Message)
- func (c *TorConnector) NewAddress(endp string) (net.Addr, error)
- func (c *TorConnector) Resolve(addr *Address) net.Addr
- func (c *TorConnector) Sample(num int, skip *Address) []*Address
- func (c *TorConnector) Send(ctx context.Context, dst net.Addr, pkt *Packet) (err error)
- type TorTransport
- type TorTransportConfig
- type Transport
- type TransportConfig
- type UDPConnector
- func (c *UDPConnector) Epoch(epoch int)
- func (c *UDPConnector) Learn(addr *Address, endp net.Addr) error
- func (c *UDPConnector) Listen(ctx context.Context, ch chan Message)
- func (c *UDPConnector) NewAddress(endp string) (net.Addr, error)
- func (c *UDPConnector) Resolve(addr *Address) net.Addr
- func (c *UDPConnector) Sample(num int, skip *Address) []*Address
- func (c *UDPConnector) Send(ctx context.Context, dst net.Addr, pkt *Packet) error
- type UDPTransport
Constants ¶
const ( //================================================================== // IMPORTANT: Requests MUST have odd values, responses MUST be even! // (If you have multiple responses for a single request, leave out // odd numbers from sequence) //================================================================== ReqPING = 1 // PING to check if a node is alive RespPING = 2 // response to PING ReqNODE = 3 // FIND_NODE returns a list of nodes "near" the requested one RespNODE = 4 // response to FIND_NODE ReqRELAY = 5 // relay message to another node (response-less) )
type values for node commands
const ( MsgfRelay = 1 // Message was forwarded (sender != originator) MsgfDrop = 2 // Drop message without processing (cover traffic) )
message flags
const ( // Alpha is the concurrency parameter Alpha = 3 // BucketTTLSecs is the lifetime of a drop in a bucket (in seconds) BucketTTLSecs = 300 // PingTimeout is the grace period for "still-alive" checks PingTimeout = 10 * time.Second )
const ( SampleCache = 100 MaxSample = 5 )
Internal constants
const HdrSize = 80
HdrSize is the size of the message header in bytes.
const (
// MaxMsgSize defines the maximum message size
MaxMsgSize = 65530
)
Variables ¶
var ( ErrHandlerUsed = fmt.Errorf("Handler in use") ErrHandlerUnused = fmt.Errorf("Handler not in use") )
Error codes used
var ( ErrNodeTimeout = fmt.Errorf("Operation timed out") ErrNodeRemote = fmt.Errorf("No remote nodes allowed") ErrNodeConnectorSet = fmt.Errorf("Connector for node already set") ErrNodeSendNoReceiver = fmt.Errorf("Send has no recipient") ErrNodeResolve = fmt.Errorf("Can't resolve network address") )
Error codes
var ( ErrPacketSenderMismatch = fmt.Errorf("Sender not matching message header") ErrPacketIntegrity = fmt.Errorf("Packet integrity violated") ErrPacketSizeMismatch = fmt.Errorf("Packet size mismatch") )
Error messages
var ( // AddrSize is the size of an address in bytes AddrSize uint16 = 32 // ErrAddressInvalid error message for malformed addresses ErrAddressInvalid = fmt.Errorf("Invalid address") )
var ( ErrServiceRequest = fmt.Errorf("Request failed or invalid") ErrServiceRequestUnknown = fmt.Errorf("Unknown request") ErrServiceResponseUnknown = fmt.Errorf("Unknown response") )
Error messages
var ( ErrTransSenderMismatch = fmt.Errorf("Sender mismatch") ErrTransUnknownSender = fmt.Errorf("Unknown sender") ErrTransPackaging = fmt.Errorf("Failed to create packet") ErrTransMarshalling = fmt.Errorf("Failed to marshal message") ErrTransOpened = fmt.Errorf("Transport is opened") ErrTransClosed = fmt.Errorf("Transport is closed") ErrTransWrite = fmt.Errorf("Failed write to remote") ErrTransWriteShort = fmt.Errorf("Short write to remote") ErrTransAddressDup = fmt.Errorf("Address already registered") ErrTransUnknownReceiver = fmt.Errorf("Unknown receiver") ErrTransAddressInvalid = fmt.Errorf("Invalid network address") ErrTransInvalidConfig = fmt.Errorf("Invalid configuration type") )
Error codes
var (
ErrLookupFailed = fmt.Errorf("Lookup failed")
)
Error codes
var ( // ErrMessageParse if message parsing from binary data failed ErrMessageParse = fmt.Errorf("Failed to parse message") )
var ( // KBuckets is the number of entries in a bucket per address bit. KBuckets int = 20 )
var (
NodeTick = 1 * time.Minute
)
constants
Functions ¶
This section is empty.
Types ¶
type Address ¶
type Address struct {
Data []byte `size:"32"` // address data of size "(ADDRESS_BITS+7)/8"
}
Address encapsulates data representing the object identifier.
func NewAddress ¶
NewAddress creates a new address from a binary object
func NewAddressFromKey ¶
NewAddressFromKey generate an address from public key
func NewAddressFromString ¶
NewAddressFromString recreates an address from string label
func (*Address) Distance ¶
Distance returns the distance between two addresses. The distance metric is based on XOR'ing the address values.
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket is used to store nodes depending on their distance to a reference node (the local node usually). All addresses in one bucket have the same distance value. A bucket is ordered: LRU addresses are at the beginning of the list, the MRU addresses are at the end (Kademlia scheme)
func (*Bucket) Contains ¶
Contains checks if address is already in the bucket and returns its index in the list (or -1 if not found)
type BucketList ¶
type BucketList struct {
// contains filtered or unexported fields
}
BucketList is a list of buckets (one for each address bit)
func NewBucketList ¶
func NewBucketList(addr *Address, ping *PingService) *BucketList
NewBucketList returns a new BucketList with given address as reference point for distances.
func (*BucketList) Add ¶
func (bl *BucketList) Add(addr *Address)
Add a new peer to the routing table (possibly)
func (*BucketList) Closest ¶
func (bl *BucketList) Closest(n int) (res []*Address)
Closest returns the n closest nodes we know of The number of returned nodes can be smaller if the node does not know about that many more nodes. Addresses are ordered by distance and MRU.
func (*BucketList) Run ¶
func (bl *BucketList) Run(ctx context.Context)
Run the processing loop for the bucket list.
type BucketListTask ¶
type BucketListTask struct {
// contains filtered or unexported fields
}
BucketListTask describes a maintenance job on the bucket list
type Connector ¶
type Connector interface { // Send packet to endpoint (low-level transport) Send(context.Context, net.Addr, *Packet) error // Listen to messages from transport Listen(context.Context, chan Message) // Learn network address of node address Learn(*Address, net.Addr) error // Resolve the network address of a node address Resolve(*Address) net.Addr // NewAddress to instaniate a new endpoint address NewAddress(string) (net.Addr, error) // Sample given number of nodes with network addresses // stored in cache. Sample(int, *Address) []*Address // Epoch step: perform periodic tasks Epoch(int) }
Connector can send and receive message over a transport layer.
type Endpoint ¶
Endpoint specifies a node on the network
func NewEndpoint ¶
NewEndpoint creates a new instance for given address,endp pair
type FindNodeMsg ¶
FindNodeMsg for FIND_NODE requests
func (*FindNodeMsg) Set ¶
func (m *FindNodeMsg) Set(addr *Address) *FindNodeMsg
Set the additional address field
func (*FindNodeMsg) String ¶
func (m *FindNodeMsg) String() string
String returns human-readable message
type FindNodeRespMsg ¶
FindNodeRespMsg for FIND_NODE responses
func (*FindNodeRespMsg) Add ¶
func (m *FindNodeRespMsg) Add(e *Endpoint)
Add an lookup entry to the list
func (*FindNodeRespMsg) String ¶
func (m *FindNodeRespMsg) String() string
String returns human-readable message
type HandlerList ¶
type HandlerList struct {
// contains filtered or unexported fields
}
HandlerList maps an integer to a message handler instance.
func NewHandlerList ¶
func NewHandlerList() *HandlerList
NewHandlerList instantiates a new list of handler mappings.
func (*HandlerList) Add ¶
func (r *HandlerList) Add(id int, f MessageHandler) error
Add a message handler for given integer to list.
func (*HandlerList) Remove ¶
func (r *HandlerList) Remove(id int) error
Remove handler for given integer from list.
type LocalAddress ¶
type LocalAddress struct {
Name string
}
LocalAddress is the network address (net.Addr) of a local node.
func NewLocalAddress ¶
func NewLocalAddress(name string) *LocalAddress
NewLocalAddress creates a new address with give name
func (*LocalAddress) Network ¶
func (a *LocalAddress) Network() string
Network returns the network label of the address
func (*LocalAddress) String ¶
func (a *LocalAddress) String() string
String returns the human-readable network address
type LocalConnector ¶
type LocalConnector struct {
// contains filtered or unexported fields
}
LocalConnector is used in LocalTransport
func (*LocalConnector) Epoch ¶ added in v1.2.4
func (c *LocalConnector) Epoch(epoch int)
Epoch step: perform periodic tasks
func (*LocalConnector) Learn ¶
func (c *LocalConnector) Learn(addr *Address, endp net.Addr) error
Learn network address of node address
func (*LocalConnector) Listen ¶
func (c *LocalConnector) Listen(ctx context.Context, ch chan Message)
Listen to messages from "outside" not necessary in local transport
func (*LocalConnector) NewAddress ¶
func (c *LocalConnector) NewAddress(endp string) (net.Addr, error)
NewAddress returns a new network address for the transport based on an endpoint specification.
func (*LocalConnector) Resolve ¶
func (c *LocalConnector) Resolve(addr *Address) net.Addr
Resolve node address into a network address
type LocalTransport ¶
type LocalTransport struct {
// contains filtered or unexported fields
}
LocalTransport handles all common transport functionality and is able to route messages to local nodes
func NewLocalTransport ¶
func NewLocalTransport() *LocalTransport
NewLocalTransport instantiates a local transport implementation
func (*LocalTransport) Close ¶ added in v1.2.2
func (t *LocalTransport) Close() error
Close transport
func (*LocalTransport) Open ¶ added in v1.2.2
func (t *LocalTransport) Open(cfg TransportConfig) error
Open transport based on configuration
type LookupService ¶
type LookupService struct {
ServiceImpl
}
LookupService to resolve node addresses (routing)
func NewLookupService ¶
func NewLookupService() *LookupService
NewLookupService creates a new service instance
func (*LookupService) Lookup ¶
func (s *LookupService) Lookup(ctx context.Context, addr *Address, resolver Query, timeout time.Duration) (res interface{}, err error)
Lookup with specific resolver logic to handle mutlitple lookup scenarios.
func (*LookupService) LookupNode ¶
func (s *LookupService) LookupNode(ctx context.Context, addr *Address, timeout time.Duration) (entry *Endpoint, err error)
LookupNode a node endpoint address.
func (*LookupService) Name ¶
func (s *LookupService) Name() string
Name is a human-readble and short service description like "PING"
func (*LookupService) NewMessage ¶
func (s *LookupService) NewMessage(mt int) Message
NewMessage creates an empty service message of given type
type Message ¶
type Message interface { // Header of message (common data) Header() *MsgHeader // Data returns the binary representation of the message Data() []byte // String returns a human-readable message String() string }
Message interface
func NewFindNodeMsg ¶
func NewFindNodeMsg() Message
NewFindNodeMsg creates an empty FIND_NODE message
func NewFindNodeRespMsg ¶
func NewFindNodeRespMsg() Message
NewFindNodeRespMsg creates an empty FIND_NODE response
type MessageFactory ¶
MessageFactory reassembles messages from binary data
type MessageHandler ¶
MessageHandler is a (async) function that handles a message
type MsgHeader ¶
type MsgHeader struct { Size uint16 `order:"big"` // Size of message (including size) Type uint16 `order:"big"` // Message type (see constants) Flags uint32 `order:"big"` // Message flags (see constants) TxID uint64 `order:"big"` // transaction identifier Sender *Address Receiver *Address }
MsgHeader (common header for requests and responses, 80 bytes)
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a local network peer
func NewNode ¶
func NewNode(prv *ed25519.PrivateKey) (n *Node, err error)
NewNode instantiates a new local node with given private key.
func (*Node) AddService ¶
AddService to add a new service running on the node.
func (*Node) LookupService ¶ added in v1.2.2
func (n *Node) LookupService() *LookupService
LookupService returns the PING service instance
func (*Node) NewNetworkAddr ¶
NewNetworkAddr returns the network address for endpoint (transport-specific)
func (*Node) NextID ¶ added in v1.2.2
NextID returns the next unique identifier for this node context
func (*Node) PingService ¶ added in v1.2.2
func (n *Node) PingService() *PingService
PingService returns the PING service instance
func (*Node) RelayService ¶ added in v1.2.2
func (n *Node) RelayService() *RelayService
RelayService returns the RELAY service instance
func (*Node) RelayedMessage ¶
RelayedMessage creates a nested relay message
func (*Node) Resolve ¶
Resolve peer address to network address This will only deliver a result if the address has been learned before by the transport connector. Unknown endpoints must be resolved with the LookupService.
func (*Node) Sample ¶
Sample returns a random collection of node/network address pairs this node has learned during up-time.
func (*Node) Service ¶
Service returns the named service instance for node. Useful for external services that are unknown within the framework.
type Packet ¶
type Packet struct { Size uint16 `order:"big"` // size of packet (including this field) KXT []byte `size:"32"` // Key Exchange Token Body []byte `size:"*"` // encrypted body }
Packet data structure
func NewPacket ¶
func NewPacket(msg Message, skey *ed25519.PrivateKey) (*Packet, error)
NewPacket creates a new packet from a message.
func NewPacketFromData ¶
func NewPacketFromData(buf []byte, sender *ed25519.PrivateKey, receiver *ed25519.PublicKey) (*Packet, error)
NewPacketFromData creates a new packet from a binary object.
func (*Packet) Unpack ¶
func (p *Packet) Unpack(receiver *ed25519.PrivateKey) ([]byte, error)
Unpack a packet
func (*Packet) Unwrap ¶
func (p *Packet) Unwrap(receiver *ed25519.PrivateKey, mf MessageFactory) (Message, error)
Unwrap a packet
type PingService ¶
type PingService struct {
ServiceImpl
}
PingService responds to PING requests from remote peer
func NewPingService ¶
func NewPingService() *PingService
NewPingService creates a new service instance
func (*PingService) Name ¶
func (s *PingService) Name() string
Name is a human-readble and short service description like "PING"
func (*PingService) NewMessage ¶
func (s *PingService) NewMessage(mt int) Message
NewMessage creates an empty service message of given type
type Query ¶
Query remote peer for given address; result depends on query implementation. It is either an error, a boolean "done" signal (no result) or a result instance. In this service the "final" result is of type Endoint; other services (like DHT) can use their own results (Value). If the result is an address list, the referenced nodes are queried for a result.
type RelayMsg ¶
type RelayMsg struct { MsgHeader NextHop *Endpoint // next hop address Pkt *Packet // packet to deliver to next hop }
RelayMsg is used to forward packets to nodes. The forwarded packet can itself be a RelayMsg, thus allowing a nested relay path (onion-like)
type RelayService ¶
type RelayService struct {
ServiceImpl
}
RelayService to forward messages to other nodes.
func NewRelayService ¶
func NewRelayService() *RelayService
NewRelayService creates a new service instance
func (*RelayService) Name ¶
func (s *RelayService) Name() string
Name is a human-readble and short service description like "PING"
func (*RelayService) NewMessage ¶
func (s *RelayService) NewMessage(mt int) Message
NewMessage creates an empty service message of given type
type Service ¶
type Service interface { // Name is a human-readble and short service description like "PING" Name() string // Node the service is running on Node() *Node // Respond to a service request from peer. // The bool return value indicates whether the message has been processed // or not and if there was an error message with it. Respond(context.Context, Message) (bool, error) // Listen to service responses from peer. // The bool return value indicates whether the message has been processed // or not and if there was an error message with it. Listen(context.Context, Message) (bool, error) // Send a message to network Send(context.Context, Message) error // NewMessage creates an empty service message of given type. // The type must be known to the service. NewMessage(mt int) Message // contains filtered or unexported methods }
Service is running on a node and provides: - a responder for requests with matching message type - a listener for service messages with matching TxId Service is the building block for upper levels of the protocol stack.
type ServiceImpl ¶
type ServiceImpl struct {
// contains filtered or unexported fields
}
ServiceImpl is a basic implementation of a Service instance and the building block for custom services implementing new functionality.
func NewServiceImpl ¶
func NewServiceImpl() *ServiceImpl
NewServiceImpl returns a new basic service instance (NOP)
func (*ServiceImpl) MessageFactory ¶
func (s *ServiceImpl) MessageFactory(mt int) Message
MessageFactory returns an empty message for a given type
func (*ServiceImpl) Node ¶
func (s *ServiceImpl) Node() *Node
Node returns the node the service is running on
func (*ServiceImpl) Send ¶
func (s *ServiceImpl) Send(ctx context.Context, msg Message) error
Send a message from this node to the network
func (*ServiceImpl) Task ¶
func (s *ServiceImpl) Task(ctx context.Context, m Message, f *TaskHandler) (err error)
Task is a generic wrapper for tasks running on a local node. It sends an initial message 'm'; responses are handled by 'f'. If 'f' returns true, no further responses from the receiver are expected.
type ServiceList ¶
type ServiceList struct {
// contains filtered or unexported fields
}
ServiceList for all services registered on a node
func (*ServiceList) MessageFactory ¶
func (sl *ServiceList) MessageFactory(buf []byte) (Message, error)
MessageFactory re-creates a message from binary data.
type String ¶
type String struct { Len uint16 `order:"big"` // length of string Data []byte `size:"Len"` // string data }
String is a sequence of unicode runes in binary format
type TaskHandler ¶
type TaskHandler struct {
// contains filtered or unexported fields
}
TaskHandler is used to notify listener of messages during task processing
type TorAddress ¶ added in v1.2.2
type TorAddress struct {
// contains filtered or unexported fields
}
TorAddress is an onion address as each node is listing for incoming packets as a "hidden service".
func NewTorAddress ¶ added in v1.2.2
func NewTorAddress(addr *Address) (*TorAddress, error)
NewTorAddress creates a new onion address from the P2P address of a node.
func (*TorAddress) Network ¶ added in v1.2.2
func (a *TorAddress) Network() string
Network returns the network label of the address
func (*TorAddress) String ¶ added in v1.2.2
func (a *TorAddress) String() string
String returns the human-readable network address
type TorConnection ¶ added in v1.2.4
type TorConnection struct {
// contains filtered or unexported fields
}
TorConnection is an open TCP connection to a hidden servoice of a peer
func (*TorConnection) Expired ¶ added in v1.2.4
func (c *TorConnection) Expired() bool
Expired connection?
type TorConnector ¶ added in v1.2.2
type TorConnector struct {
// contains filtered or unexported fields
}
TorConnector is a stub between a node and the Tor-based transport implementation.
func NewTorConnector ¶ added in v1.2.2
func NewTorConnector(trans *TorTransport, node *Node, port int) (*TorConnector, error)
NewTorConnector creates a connector on transport for a given node
func (*TorConnector) Epoch ¶ added in v1.2.4
func (c *TorConnector) Epoch(epoch int)
Epoch step: perform periodic tasks
func (*TorConnector) Learn ¶ added in v1.2.2
func (c *TorConnector) Learn(addr *Address, endp net.Addr) error
Learn network address of node address is obsolete if Tor transport is used; the network address can be computed from the P2P address.
func (*TorConnector) Listen ¶ added in v1.2.2
func (c *TorConnector) Listen(ctx context.Context, ch chan Message)
Listen on an UDP address/port for incoming packets
func (*TorConnector) NewAddress ¶ added in v1.2.2
func (c *TorConnector) NewAddress(endp string) (net.Addr, error)
NewAddress returns a new onion address for an endpoint
func (*TorConnector) Resolve ¶ added in v1.2.2
func (c *TorConnector) Resolve(addr *Address) net.Addr
Resolve node address into a network address is a deterministic function if Tor transport is used.
type TorTransport ¶ added in v1.2.2
type TorTransport struct {
// contains filtered or unexported fields
}
TorTransport handles the transport of packets between nodes over Tor curcuits / hidden services.
func NewTorTransport ¶ added in v1.2.2
func NewTorTransport() *TorTransport
NewTorTransport instantiates a new Tor transport layer where the listening socket is bound to the specified address (host:port).
func (*TorTransport) Open ¶ added in v1.2.2
func (t *TorTransport) Open(cfg TransportConfig) (err error)
Open transport based on configuration
type TorTransportConfig ¶ added in v1.2.2
type TorTransportConfig struct { // Ctrl specifies the Tor control interface. It is formatted like // "network:endp", where 'network' is either "tcp" (for TCP/IP) or // "unix" (for a local Unix socket). 'endp' specifies the endpoint // depending on the network; it is "host:port" for "tcp" and a file // path in case of a local Unix socket. // The same host (either "host" as deined or localhos) must have the // defined SOCKS ports open for access to Tor cuircuits. Ctrl string `json:"ctrl"` // Auth is the authentication password/cookie. If a cookie is used // (only applicable for local Tor service instances), the value is // set dynamically (and not in a persistent configuration file). Auth string `json:"auth"` // HSHost refers to the host running hidden service endpoints HSHost string `json:"hshost"` // PeerTTL defines (in seconds) how long connections are kept-alive // after a message has been send. PeerTTL int `json:"peerTTL"` }
TorTransportConfig specifies the configuration parameters required to instanciate a Tor-based transport for the P2P network.
func (*TorTransportConfig) TransportType ¶ added in v1.2.2
func (c *TorTransportConfig) TransportType() string
TransportType returns the kind of transport implementation targeted by the configuration information.
type Transport ¶
type Transport interface { // Open transport based on configuration Open(TransportConfig) error // Register a node for participation in this transport Register(context.Context, *Node, string) error // Close transport Close() error }
Transport abstraction: Every endpoint (on a local machine) registers with its address and receives channels for communication (incoming and outgoing messages). The transfer process needs to be started with the 'Run()' method for its message pump to work.
type TransportConfig ¶ added in v1.2.2
type TransportConfig interface {
TransportType() string // return type of associated transport
}
TransportConfig is used for transport-specific configurations
type UDPConnector ¶
type UDPConnector struct {
// contains filtered or unexported fields
}
UDPConnector is a stub between a node and the UDP transport implementation.
func NewUDPConnector ¶
func NewUDPConnector(trans *UDPTransport, node *Node, addr *net.UDPAddr) *UDPConnector
NewUDPConnector creates an empty instance for node at given network address
func (*UDPConnector) Epoch ¶ added in v1.2.4
func (c *UDPConnector) Epoch(epoch int)
Epoch step: perform periodic tasks
func (*UDPConnector) Learn ¶
func (c *UDPConnector) Learn(addr *Address, endp net.Addr) error
Learn network address of node address
func (*UDPConnector) Listen ¶
func (c *UDPConnector) Listen(ctx context.Context, ch chan Message)
Listen on an UDP address/port for incoming packets
func (*UDPConnector) NewAddress ¶
func (c *UDPConnector) NewAddress(endp string) (net.Addr, error)
NewAddress returns a new UDP address for an endpoint
func (*UDPConnector) Resolve ¶
func (c *UDPConnector) Resolve(addr *Address) net.Addr
Resolve node address into a network address
type UDPTransport ¶
type UDPTransport struct {
// contains filtered or unexported fields
}
UDPTransport handles the transport of packets between nodes over the internet using the UDP protocol.
func NewUDPTransport ¶
func NewUDPTransport() *UDPTransport
NewUDPTransport instantiates a new UDP transport layer where the listening socket is bound to the specified address (host:port).
func (*UDPTransport) Open ¶ added in v1.2.2
func (t *UDPTransport) Open(cfg TransportConfig) error
Open transport based on configuration