p2pc

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package p2pc extends udpc to provide P2P functionality

Index

Constants

View Source
const (
	P2P_CONNECT_TRIES   = 3
	P2P_RECONNECT_TRIES = 3
)
View Source
const (
	RELAY_CONNECT_TRIES      = 3
	RELAY_RECONNECT_TRIES    = 4
	RELAY_PEER_AWAIT_TIMEOUT = time.Second * 20
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Relay Server Address
	// Providing an address (non-nil) will ensure that all relay connections from this client
	// will use the server with this address
	RelayAddr *net.UDPAddr
}

P2P Client Manager

type Connection

type Connection struct {

	// Client ID
	ClientId string

	// Exit Channel
	Exit chan bool
	// Closed Status
	Closed bool
	// contains filtered or unexported fields
}

P2P Client Connection

func (*Connection) Close

func (c *Connection) Close(reason string)

func (*Connection) IsConnected

func (c *Connection) IsConnected() bool

If Connection is active

func (*Connection) OpenStream

func (c *Connection) OpenStream(data map[string]string) (stream *udp.Stream, err error)

Open Stream to Peer

func (*Connection) String

func (c *Connection) String() string

Stringify

type Manager

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

P2P Client Manager

func New

func New(
	log *logrus.Logger,
	config Config,
	client *udpc.Client,
	connectionHandler NewConnectionHandler,
) (m *Manager, err error)

Create new Manager

func (*Manager) CloseAll

func (m *Manager) CloseAll()

Close All Connections

func (*Manager) CloseConnection

func (m *Manager) CloseConnection(cid string, reason string)

Close Connection

func (*Manager) ConnectById

func (m *Manager) ConnectById(peerId string, mode p2p.ConnectionMode) (conn *Connection, err error)

Connect to Client by ID

func (*Manager) ConnectByTag

func (m *Manager) ConnectByTag(tag string, mode p2p.ConnectionMode) (conn *Connection, err error)

Connect to Client by Tag

func (*Manager) SetStreamHandler

func (m *Manager) SetStreamHandler(handler udp.StreamHandler)

Set New Stream Handler

type NewConnectionHandler

type NewConnectionHandler func(c *Connection)

Called on new Connection

Jump to

Keyboard shortcuts

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