Documentation
¶
Index ¶
- Variables
- func SetDefaultSymmAlgo(symmAlgo func(secure.ProvideSecretKey) secure.SymmAlgo)
- type Config
- type NodeInfo
- type OnPeer
- type OnPeerLeave
- type Option
- func KeepAlivePeriod(period time.Duration) Option
- func ListenIPv4Only() Option
- func ListenIPv6Only() Option
- func ListenPeerCurve25519(privateKey string) Option
- func ListenPeerID(id string) Option
- func ListenPeerLeave(onPeerLeave OnPeerLeave) Option
- func ListenPeerSecure() Option
- func ListenPeerUp(onPeer OnPeer) Option
- func ListenUDPPort(port int) Option
- func MinDiscoPeriod(period time.Duration) Option
- func PeerAlias1(alias string) Option
- func PeerAlias2(alias string) Option
- func PeerMeta(key string, value string) Option
- func PeerSilenceMode() Option
- type PacketConn
- func (c *PacketConn) Close() error
- func (c *PacketConn) ControllerManager() disco.ControllerManager
- func (c *PacketConn) LocalAddr() net.Addr
- func (c *PacketConn) NodeInfo() NodeInfo
- func (c *PacketConn) PeerMeta(peerID disco.PeerID) url.Values
- func (c *PacketConn) PeerStore() udp.PeerStore
- func (c *PacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (c *PacketConn) ServerStream() io.ReadWriter
- func (c *PacketConn) ServerURL() string
- func (c *PacketConn) SetDeadline(t time.Time) error
- func (c *PacketConn) SetReadBuffer(bytes int) error
- func (c *PacketConn) SetReadDeadline(t time.Time) error
- func (c *PacketConn) SetTransportMode(mode TransportMode)
- func (c *PacketConn) SetWriteBuffer(bytes int) error
- func (c *PacketConn) SetWriteDeadline(t time.Time) error
- func (c *PacketConn) SharedKey(peerID disco.PeerID) ([]byte, error)
- func (c *PacketConn) TryLeadDisco(peerID disco.PeerID)
- func (c *PacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
- type TransportMode
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoRelayPeer = errors.New("no relay peer")
)
Functions ¶
func SetDefaultSymmAlgo ¶
func SetDefaultSymmAlgo(symmAlgo func(secure.ProvideSecretKey) secure.SymmAlgo)
Types ¶
type OnPeerLeave ¶ added in v0.9.0
type Option ¶
func KeepAlivePeriod ¶
func ListenIPv4Only ¶
func ListenIPv4Only() Option
func ListenIPv6Only ¶
func ListenIPv6Only() Option
func ListenPeerCurve25519 ¶
func ListenPeerID ¶
func ListenPeerLeave ¶ added in v0.9.0
func ListenPeerLeave(onPeerLeave OnPeerLeave) Option
func ListenPeerSecure ¶
func ListenPeerSecure() Option
func ListenPeerUp ¶
func ListenUDPPort ¶
func MinDiscoPeriod ¶
func PeerAlias1 ¶
func PeerAlias2 ¶
func PeerSilenceMode ¶
func PeerSilenceMode() Option
type PacketConn ¶ added in v0.7.12
type PacketConn struct {
// contains filtered or unexported fields
}
func ListenPacket ¶
func ListenPacket(peermap *disco.Server, opts ...Option) (*PacketConn, error)
ListenPacket same as ListenPacketContext, but no context required
func ListenPacketContext ¶
func ListenPacketContext(ctx context.Context, server *disco.Server, opts ...Option) (*PacketConn, error)
ListenPacketContext listen the p2p network for read/write packets
func (*PacketConn) Close ¶ added in v0.7.12
func (c *PacketConn) Close() error
Close closes the connection. Any blocked ReadFrom or WriteTo operations will be unblocked and return errors.
func (*PacketConn) ControllerManager ¶ added in v0.7.12
func (c *PacketConn) ControllerManager() disco.ControllerManager
ControllerManager makes changes attempting to move the current state towards the desired state
func (*PacketConn) LocalAddr ¶ added in v0.7.12
func (c *PacketConn) LocalAddr() net.Addr
LocalAddr returns the local network address, if known.
func (*PacketConn) NodeInfo ¶ added in v0.11.3
func (c *PacketConn) NodeInfo() NodeInfo
NodeInfo get information about this node
func (*PacketConn) PeerMeta ¶ added in v0.7.13
func (c *PacketConn) PeerMeta(peerID disco.PeerID) url.Values
PeerMeta find peer metadata from all found peers
func (*PacketConn) PeerStore ¶ added in v0.7.12
func (c *PacketConn) PeerStore() udp.PeerStore
PeerStore stores the found peers
func (*PacketConn) ReadFrom ¶ added in v0.7.12
ReadFrom reads a packet from the connection, copying the payload into p. It returns the number of bytes copied into p and the return address that was on the packet. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Callers should always process the n > 0 bytes returned before considering the error err. ReadFrom can be made to time out and return an error after a fixed time limit; see SetDeadline and SetReadDeadline.
func (*PacketConn) ServerStream ¶ added in v0.7.12
func (c *PacketConn) ServerStream() io.ReadWriter
ServerStream is the connection stream to the peermap server
func (*PacketConn) ServerURL ¶ added in v0.7.12
func (c *PacketConn) ServerURL() string
ServerURL is the connected peermap server url
func (*PacketConn) SetDeadline ¶ added in v0.7.12
func (c *PacketConn) SetDeadline(t time.Time) error
SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.
A deadline is an absolute time after which I/O operations fail instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.
If the deadline is exceeded a call to Read or Write or to other I/O methods will return an error that wraps os.ErrDeadlineExceeded. This can be tested using errors.Is(err, os.ErrDeadlineExceeded). The error's Timeout method will return true, but note that there are other possible errors for which the Timeout method will return true even if the deadline has not been exceeded.
An idle timeout can be implemented by repeatedly extending the deadline after successful ReadFrom or WriteTo calls.
A zero value for t means I/O operations will not time out.
func (*PacketConn) SetReadBuffer ¶ added in v0.7.12
func (c *PacketConn) SetReadBuffer(bytes int) error
SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.
func (*PacketConn) SetReadDeadline ¶ added in v0.7.12
func (c *PacketConn) SetReadDeadline(t time.Time) error
SetReadDeadline sets the deadline for future ReadFrom calls and any currently-blocked ReadFrom call. A zero value for t means ReadFrom will not time out.
func (*PacketConn) SetTransportMode ¶ added in v0.8.0
func (c *PacketConn) SetTransportMode(mode TransportMode)
SetTransportMode sets func WriteTo underlying transport mode p2p.MODE_DEFAULT p2p > peer_relay > server_relay p2p.MODE_FORCE_PEER_RELAY force to peer_relay p2p.MODE_FORCE_RELAY force to server_relay
func (*PacketConn) SetWriteBuffer ¶ added in v0.7.12
func (c *PacketConn) SetWriteBuffer(bytes int) error
SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.
func (*PacketConn) SetWriteDeadline ¶ added in v0.7.12
func (c *PacketConn) SetWriteDeadline(t time.Time) error
SetWriteDeadline sets the deadline for future WriteTo calls and any currently-blocked WriteTo call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means WriteTo will not time out.
func (*PacketConn) SharedKey ¶ added in v0.7.12
func (c *PacketConn) SharedKey(peerID disco.PeerID) ([]byte, error)
SharedKey get the key shared with the peer
func (*PacketConn) TryLeadDisco ¶ added in v0.7.12
func (c *PacketConn) TryLeadDisco(peerID disco.PeerID)
TryLeadDisco try lead a peer discovery disco as soon as every minute
type TransportMode ¶ added in v0.8.0
type TransportMode string
const ( MODE_DEFAULT TransportMode = "" MODE_FORCE_PEER_RELAY TransportMode = "PEER_RELAY" MODE_FORCE_RELAY TransportMode = "RELAY" )
func (TransportMode) String ¶ added in v0.8.0
func (mode TransportMode) String() string