relay

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const Relay_Protocol_ID = "liquid-relay"

Relay_Protocol_ID the relay protocolID

Variables

View Source
var (
	// RelayAcceptTimeout .
	RelayAcceptTimeout = 10 * time.Second

	// HopConnectTimeout the relay hop connect timeout
	HopConnectTimeout = 30 * time.Second

	// StopHandshakeTimeout the relay stop handshake timeout
	StopHandshakeTimeout = 1 * time.Minute

	// HopStreamLimit .
	HopStreamLimit = 1 << 19 // 512K hops for 1M goroutines
)
View Source
var (
	// OptActive (reserved)
	OptActive = RelayOpt(0)

	// OptHop (default)
	OptHop = RelayOpt(1)
)

Functions

func GetRelayAddrAndDstPeerAddr

func GetRelayAddrAndDstPeerAddr(addr ma.Multiaddr) (relayAddr,
	dstAddr ma.Multiaddr, err error)

GetRelayAddrAndDstPeerAddr cut to obtain the address of the relay source node and destination node

func IsRelayAddr

func IsRelayAddr(addr ma.Multiaddr) bool

IsRelayAddr is the relay's muliaddr addr

func PeerInfoToRelayPeer

func PeerInfoToRelayPeer(peerId peer.ID, peerAddr []ma.Multiaddr) *pb.RelayMsg_Peer

PeerInfoToRelayPeer return the pb.RelayMsg_Peer

func ReadRelayMsg

func ReadRelayMsg(stream network.Stream) (*pb.RelayMsg, error)

ReadRelayMsg 在stream读出pb.RelayMsg格式的信息

func RelayPeerToPeerInfo

func RelayPeerToPeerInfo(p *pb.RelayMsg_Peer) (peer.ID, []ma.Multiaddr, error)

RelayPeerToPeerInfo the pb.RelayMsg_Peer to peerId and addr

func WriteRelayMsg

func WriteRelayMsg(s network.Stream, msg *pb.RelayMsg) error

WriteRelayMsg 向stream写入pb.RelayMsg格式的信息

Types

type Conn

type Conn struct {
	Stream network.Stream
}

Conn the relay conn (sAR/sRB)

func (*Conn) Close

func (c *Conn) Close() error

Close the relay stream close()

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

LocalAddr return the relay stream LocalNetAddr

func (*Conn) Read

func (c *Conn) Read(buf []byte) (int, error)

Read the relay stream read

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr return the relay stream RemoteNetAddr

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

SetDeadline in order to implement the net.Conn interface

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline in order to implement the net.Conn interface

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline in order to implement the net.Conn interface

func (*Conn) Write

func (c *Conn) Write(buf []byte) (int, error)

Write the relay stream write

type NetAddr

type NetAddr struct {
	Addr string
}

NetAddr addr

func (*NetAddr) Network

func (n *NetAddr) Network() string

Network return the "tcp"

func (*NetAddr) String

func (n *NetAddr) String() string

String return the string addr

type Relay

type Relay struct {
	// contains filtered or unexported fields
}

Relay the relay struct

func NewRelay

func NewRelay(ctx context.Context, peerId peer.ID, logger api.Logger, opts ...RelayOpt) (*Relay, error)

NewRelay return the relay struct

func (*Relay) Accept

func (r *Relay) Accept() (net.Conn, error)

Accept deal with the received relay messages

func (*Relay) Addr

func (r *Relay) Addr() net.Addr

Addr .

func (*Relay) Close

func (r *Relay) Close() error

Close .

func (*Relay) HandleHopStream

func (r *Relay) HandleHopStream(stream network.Stream, h host.Host, relayMsg *pb.RelayMsg)

HandleHopStream * 1) dial the target node and send a STOP message 2) wait for return and return a success message to the source node 3) copy the data from streams on both sides

func (*Relay) HandleStopStream

func (r *Relay) HandleStopStream(stream network.Stream, h host.Host, relayMsg *pb.RelayMsg)

HandleStopStream wrap the stream created with the trunk as really. Conn and throw it to the upper layer

type RelayOpt

type RelayOpt int

RelayOpt . OptActive/OptHop

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL