proximitytransport

package
v2.209.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: Apache-2.0, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TransportMap sync.Map

TransportMap keeps tracks of existing Transport to prevent multiple utilizations

Functions

func NewTransport

func NewTransport(ctx context.Context, l *zap.Logger, driver NativeDriver) func(h host.Host, u *tptu.Upgrader) (*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 {
	// 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

LocalAddr 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

Noop deadline methods, handled by the native driver.

func (*Conn) SetReadDeadline

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

func (*Conn) SetWriteDeadline

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

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 NativeDriver

type NativeDriver 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 NoopNativeDriver

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

func NewNoopNativeDriver added in v2.209.0

func NewNoopNativeDriver(protocolCode int, protocolName, defaultAddr string) *NoopNativeDriver

func (*NoopNativeDriver) CloseConnWithPeer

func (d *NoopNativeDriver) CloseConnWithPeer(_ string)

func (*NoopNativeDriver) DefaultAddr

func (d *NoopNativeDriver) DefaultAddr() string

func (*NoopNativeDriver) DialPeer

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

func (*NoopNativeDriver) ProtocolCode

func (d *NoopNativeDriver) ProtocolCode() int

func (*NoopNativeDriver) ProtocolName

func (d *NoopNativeDriver) ProtocolName() string

func (*NoopNativeDriver) SendToPeer

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

func (*NoopNativeDriver) SetDefaultAddr added in v2.209.0

func (d *NoopNativeDriver) SetDefaultAddr(protocolAddr string)

func (*NoopNativeDriver) SetProtocolCode added in v2.209.0

func (d *NoopNativeDriver) SetProtocolCode(protocolCode int)

func (*NoopNativeDriver) SetProtocolName added in v2.209.0

func (d *NoopNativeDriver) SetProtocolName(protocolName string)

func (*NoopNativeDriver) Start

func (d *NoopNativeDriver) Start(_ string)

func (*NoopNativeDriver) Stop

func (d *NoopNativeDriver) Stop()

type ProximityTransport

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

ProximityTransport represents any device by which you can connect to and accept connections from other peers.

func (*ProximityTransport) CanDial

func (t *ProximityTransport) CanDial(remoteMa ma.Multiaddr) bool

CanDial returns true if this transport believes it can dial the given multiaddr.

func (*ProximityTransport) Dial

func (t *ProximityTransport) Dial(ctx context.Context, remoteMa ma.Multiaddr, remotePID peer.ID) (tpt.CapableConn, error)

Dial dials the peer at the remote address. With proximity connections (e.g. MC, BLE, Nearby) you can only dial a device that is already connected with the native driver.

func (*ProximityTransport) HandleFoundPeer

func (t *ProximityTransport) HandleFoundPeer(sRemotePID string) bool

HandleFoundPeer is called by the native driver when a new peer is found. Adds the peer in the PeerStore and initiates a connection with it

func (*ProximityTransport) HandleLostPeer

func (t *ProximityTransport) HandleLostPeer(sRemotePID string)

HandleLostPeer is called by the native driver when the connection with the peer is lost. Closes connections with the peer.

func (*ProximityTransport) Listen

func (t *ProximityTransport) Listen(localMa ma.Multiaddr) (tpt.Listener, error)

Listen listens on the given multiaddr. Proximity connections can't listen on more than one listener.

func (*ProximityTransport) Protocols

func (t *ProximityTransport) Protocols() []int

Protocols returns the set of protocols handled by this transport.

func (*ProximityTransport) Proxy

func (t *ProximityTransport) Proxy() bool

Proxy returns true if this transport proxies.

func (*ProximityTransport) ReceiveFromPeer

func (t *ProximityTransport) ReceiveFromPeer(remotePID string, payload []byte)

ReceiveFromPeer is called by native driver when peer's device sent data.

func (*ProximityTransport) String

func (t *ProximityTransport) String() string

Jump to

Keyboard shortcuts

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