Documentation ¶
Overview ¶
Package p2pc extends udpc to provide P2P functionality
Index ¶
- Constants
- type Config
- type Connection
- type ConnectionHandler
- type Manager
- func (m *Manager) CloseAll()
- func (m *Manager) CloseConnection(cid string, reason string)
- func (m *Manager) ConnectById(peerId string, mode p2p.ConnectionMode) (conn *Connection, err error)
- func (m *Manager) ConnectByTag(tag string, mode p2p.ConnectionMode) (conn *Connection, err error)
- func (m *Manager) SetConnectionHandler(handler ConnectionHandler)
- func (m *Manager) SetMessageStreamHandler(handler MessageStreamHandler)
- func (m *Manager) SetStreamHandler(handler udp.StreamHandler)
- type MessageHandler
- type MessageStream
- type MessageStreamHandler
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) OpenMessageStream ¶
func (c *Connection) OpenMessageStream() (ms *MessageStream, err error)
func (*Connection) OpenStream ¶
Open Stream to Peer
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
P2P Client Manager
func (*Manager) CloseConnection ¶
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) SetConnectionHandler ¶
func (m *Manager) SetConnectionHandler(handler ConnectionHandler)
Set New Connection Handler
func (*Manager) SetMessageStreamHandler ¶
func (m *Manager) SetMessageStreamHandler(handler MessageStreamHandler)
Set Message Stream Handler
func (*Manager) SetStreamHandler ¶
func (m *Manager) SetStreamHandler(handler udp.StreamHandler)
Set New Stream Handler
type MessageHandler ¶
type MessageHandler func(mc *MessageStream, msg *network.Message)
Message Handler
type MessageStream ¶
type MessageStream struct { Conn *Connection // Exit channel Exit chan bool // Message Stream closed Closed bool // contains filtered or unexported fields }
Message Stream
func NewMessageStream ¶
func NewMessageStream(conn *Connection, stream *udp.Stream) *MessageStream
Create a MessageStream
func (*MessageStream) Listen ¶
func (mc *MessageStream) Listen(mh MessageHandler) (err error)
Listen for messages
func (*MessageStream) SendAndRead ¶
If the stream is not actively read, this function sends and reads a single message This method SHOULD NOT BE USED if the stream is actively being read. Just use the Send function.
type MessageStreamHandler ¶
type MessageStreamHandler func(ms *MessageStream)
Called on new MessageStream
Click to show internal directories.
Click to hide internal directories.