tunnel

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: Apache-2.0 Imports: 59 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxReadSize = 4096

	DailRetryTime = 3
	DailSleepTime = 500 * time.Microsecond

	RetryTime     = 3
	RetryInterval = 2 * time.Second
)
View Source
const (
	UDP       = "udp"
	TCP       = "tcp"
	Websocket = "ws"
	Quic      = "quic"
)

Variables

This section is empty.

Functions

func AddCircuitAddrsToPeer

func AddCircuitAddrsToPeer(peer *peer.AddrInfo, relayPeers RelayMap) error

func AppendMultiaddrs

func AppendMultiaddrs(maddrs []ma.Multiaddr, dest ma.Multiaddr) []ma.Multiaddr

AppendMultiaddrs append a maddr into maddrs, do nothing if contains

func BootstrapConnect

func BootstrapConnect(ctx context.Context, ph p2phost.Host, bootstrapPeers RelayMap) error

BootstrapConnect tries to connect to a list of bootstrap peers in a relay map. The function runs a loop to attempt connecting to each peer, and will retry if some peers fail to connect. The function returns an error if it fails to connect to all bootstrap peers after a certain period of time.

func CreateLimitOpt added in v1.13.0

func CreateLimitOpt(config *v1alpha1.TunnelLimitConfig, opts ...rcmgr.Option) (libp2p.Option, error)

func FilterCircuitMaddr

func FilterCircuitMaddr(maddrs []ma.Multiaddr) []ma.Multiaddr

func FilterPrivateMaddr

func FilterPrivateMaddr(maddrs []ma.Multiaddr) []ma.Multiaddr

func GenerateKeyPairWithString

func GenerateKeyPairWithString(s string) (crypto.PrivKey, error)

func GenerateMultiAddrString

func GenerateMultiAddrString(protocol, ip string, port int) string

GenerateMultiAddrString generate an IPv4 multi-address string by protocol, ip and port supported protocols: ["tcp", "ws", "quic"]

func GeneratePSKReader

func GeneratePSKReader(path string) (io.Reader, error)

func GeneratePeerInfo

func GeneratePeerInfo(hostname string, addrs []string) (*peer.AddrInfo, error)

func GenerateTransportOption

func GenerateTransportOption(protocol string) libp2p.Option

GenerateTransportOption generate Transport option from protocol supported protocols: ["tcp", "ws", "quic"]

func GetIPsFromInterfaces added in v1.13.2

func GetIPsFromInterfaces(listenInterfaces, extraFilteredInterfaces string) (ips []string, err error)

func IsNoFindPeerError

func IsNoFindPeerError(err error) bool

func PeerIDFromString

func PeerIDFromString(s string) (peer.ID, error)

func Register

func Register(c *v1alpha1.EdgeTunnelConfig) error

Register edgetunnel to beehive modules

func StringsToMaddrs

func StringsToMaddrs(addrStrings []string) (mas []ma.Multiaddr, err error)

StringsToMaddrs convert multi-address strings to Maddrs

Types

type EdgeTunnel

type EdgeTunnel struct {
	Config *v1alpha1.EdgeTunnelConfig
	// contains filtered or unexported fields
}

EdgeTunnel is used for solving cross subset communication

var Agent *EdgeTunnel

Agent expose the tunnel ability. TODO convert var to func

func (*EdgeTunnel) CNIAdapterStreamHandler added in v1.15.0

func (t *EdgeTunnel) CNIAdapterStreamHandler(stream network.Stream)

func (*EdgeTunnel) Enable

func (t *EdgeTunnel) Enable() bool

Enable indicates whether enable this module

func (*EdgeTunnel) GetCNIAdapterStream added in v1.15.0

func (t *EdgeTunnel) GetCNIAdapterStream(opts ProxyOptions) (*StreamConn, error)

GetCNIAdapterStream establishes a new stream with a destination peer, either directly or through a relay node, use net.conn to get income data

func (*EdgeTunnel) GetProxyStream

func (t *EdgeTunnel) GetProxyStream(opts ProxyOptions) (*StreamConn, error)

GetProxyStream establishes a new stream with a destination peer, either directly or through a relay node, by performing a handshake with the destination peer over the stream to confirm the connection. It first looks up the destination peer's ID in a cache, and if not found, generates the peer ID and adds circuit addresses to it. It then opens a new stream using the libp2p host, and performs a handshake with the destination peer over the stream. If the handshake is successful, it returns a new StreamConn object representing the stream. If any errors occur during the process, it returns an error.

func (*EdgeTunnel) Group

func (t *EdgeTunnel) Group() string

Group of EdgeTunnel

func (*EdgeTunnel) Name

func (t *EdgeTunnel) Name() string

Name of EdgeTunnel

func (*EdgeTunnel) Run

func (t *EdgeTunnel) Run()

func (*EdgeTunnel) Shutdown added in v1.13.1

func (t *EdgeTunnel) Shutdown()

func (*EdgeTunnel) Start

func (t *EdgeTunnel) Start()

Start EdgeTunnel

type ProxyOptions

type ProxyOptions struct {
	Protocol string
	NodeName string
	IP       string
	Port     int32
}

type RelayMap

type RelayMap map[string]*peer.AddrInfo

func GenerateRelayMap

func GenerateRelayMap(relayNodes []*v1alpha1.RelayNode, protocol string, listenPort int) RelayMap

func (RelayMap) ContainsPublicIP added in v1.13.1

func (r RelayMap) ContainsPublicIP() bool

type StreamAddr

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

StreamAddr implements the net.Addr interface

func (*StreamAddr) Network

func (sa *StreamAddr) Network() string

func (*StreamAddr) String

func (sa *StreamAddr) String() string

type StreamConn

type StreamConn struct {
	network.Stream
	// contains filtered or unexported fields
}

StreamConn is libp2p network.Stream wrapper, which implements the Golang net.Conn interface

func NewStreamConn

func NewStreamConn(s network.Stream) *StreamConn

func (*StreamConn) LocalAddr

func (ns *StreamConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*StreamConn) RemoteAddr

func (ns *StreamConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

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