proximitytransport

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: Apache-2.0, MIT Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Verbose = iota
	Debug
	Info
	Warn
	Error
)

Define log level for driver loggers

Variables

View Source
var TransportMap = make(map[string]*proximityTransport)

TransportMap prevents instantiating multiple Transport

View Source
var TransportMapMutex sync.RWMutex

TransportMapMutex is the mutex for the TransportMap var

Functions

func NewTransport

func NewTransport(ctx context.Context, l *zap.Logger, driver ProximityDriver) func(h host.Host, u tpt.Upgrader, rcmgr network.ResourceManager) (*proximityTransport, error)

Types

type Addr

type Addr struct {
	Address string
	// contains filtered or unexported fields
}

Addr represents a network end point address.

func (*Addr) Network

func (b *Addr) Network() string

Network returns the address's network name.

func (*Addr) String

func (b *Addr) String() string

String return's the string form of the address.

type Conn

type Conn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Conn is the equivalent of a net.Conn object. It is the result of calling the Dial or Listen functions in this package, with associated local and remote Multiaddrs.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (*Conn) LocalAddr

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

LocalAddr returns the local network address.

func (*Conn) LocalMultiaddr

func (c *Conn) LocalMultiaddr() ma.Multiaddr

LocalMultiaddr returns the local Multiaddr associated with this connection.

func (*Conn) Read

func (c *Conn) Read(payload []byte) (n int, err error)

Read reads data from the connection. Timeout handled by the native driver.

func (*Conn) RemoteAddr

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

RemoteAddr returns the remote network address.

func (*Conn) RemoteMultiaddr

func (c *Conn) RemoteMultiaddr() ma.Multiaddr

RemoteMultiaddr returns the remote Multiaddr associated with this connection.

func (*Conn) SetDeadline

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

SetDeadline does nothing

func (*Conn) SetReadDeadline

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

SetReadDeadline does nothing

func (*Conn) SetWriteDeadline

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

SetWriteDeadline does nothing

func (*Conn) Write

func (c *Conn) Write(payload []byte) (n int, err error)

Write writes data to the connection. Timeout handled by the native driver.

type Listener

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

Listener is an interface closely resembling the net.Listener interface. The only real difference is that Accept() returns Conn's of the type in this package, and also exposes a Multiaddr method as opposed to a regular Addr method.

func (*Listener) Accept

func (l *Listener) Accept() (tpt.CapableConn, error)

Accept waits for and returns the next connection to the listener. Returns a Multiaddr friendly Conn.

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the net.Listener's network address.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the listener. Any blocked Accept operations will be unblocked and return errors.

func (*Listener) Multiaddr

func (l *Listener) Multiaddr() ma.Multiaddr

Multiaddr returns the listener's (local) Multiaddr.

type NoopProximityDriver

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

func NewNoopProximityDriver

func NewNoopProximityDriver(protocolCode int, protocolName, defaultAddr string) *NoopProximityDriver

func (*NoopProximityDriver) CloseConnWithPeer

func (d *NoopProximityDriver) CloseConnWithPeer(_ string)

func (*NoopProximityDriver) DefaultAddr

func (d *NoopProximityDriver) DefaultAddr() string

func (*NoopProximityDriver) DialPeer

func (d *NoopProximityDriver) DialPeer(_ string) bool

func (*NoopProximityDriver) ProtocolCode

func (d *NoopProximityDriver) ProtocolCode() int

func (*NoopProximityDriver) ProtocolName

func (d *NoopProximityDriver) ProtocolName() string

func (*NoopProximityDriver) SendToPeer

func (d *NoopProximityDriver) SendToPeer(_ string, _ []byte) bool

func (*NoopProximityDriver) Start

func (d *NoopProximityDriver) Start(_ string)

func (*NoopProximityDriver) Stop

func (d *NoopProximityDriver) Stop()

type ProximityDriver

type ProximityDriver interface {
	// Start the native driver
	Start(localPID string)

	// Stop the native driver
	Stop()

	// Check if the native driver is connected to the remote peer
	DialPeer(remotePID string) bool

	// Send data to the remote peer
	SendToPeer(remotePID string, payload []byte) bool

	// Close the connection with the remote peer
	CloseConnWithPeer(remotePID string)

	// Return the multiaddress protocol code
	ProtocolCode() int

	// Return the multiaddress protocol name
	ProtocolName() string

	// Return the default multiaddress
	DefaultAddr() string
}

type ProximityTransport

type ProximityTransport interface {
	HandleFoundPeer(remotePID string) bool
	HandleLostPeer(remotePID string)
	ReceiveFromPeer(remotePID string, payload []byte)
	Log(level int, message string)
}

type RingBufferMap

type RingBufferMap struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RingBufferMap is a map of string:ringBuffer(aka circular buffer) The key is a peerID.

func NewRingBufferMap

func NewRingBufferMap(logger *zap.Logger, size int) *RingBufferMap

NewRingBufferMap returns a new connMgr struct The size argument is the number of packets to save in cache.

func (*RingBufferMap) Add

func (rbm *RingBufferMap) Add(peerID string, payload []byte)

Add adds the payload into a circular cache

func (*RingBufferMap) Delete

func (rbm *RingBufferMap) Delete(peerID string)

Delete cache entry

func (*RingBufferMap) Flush

func (rbm *RingBufferMap) Flush(peerID string) <-chan []byte

Flush puts the cache contents into a chan and clears it

Jump to

Keyboard shortcuts

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