Documentation ¶
Index ¶
Constants ¶
const EnvConnectID = "cid"
EnvConnectID the env key of ConnectID,the connection have different id
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Addr ¶
type Addr interface { String() string Scheme() string User() string Host() string IsServer() bool UpdateUser(string) SetServer() }
Addr the address of connection
type Conn ¶
type Conn interface { // Read reads data from the connection. // Read can be made to time out and return an Error with Timeout() == true // after a fixed time limit; see SetDeadline and SetReadDeadline. Read(b []byte) (n int, err error) // Write writes data to the connection. // Write can be made to time out and return an Error with Timeout() == true // after a fixed time limit; see SetDeadline and SetWriteDeadline. Write(b []byte) (n int, err error) // Close closes the connection. // Any blocked Read or Write operations will be unblocked and return errors. Close() error // LocalAddr returns the local network address. LocalAddr() Addr // RemoteAddr returns the remote network address. RemoteAddr() Addr }
Conn is a generic stream-oriented network connection.
Multiple goroutines may invoke methods on a Conn simultaneously.
type ConnPool ¶
type ConnPool interface { Listen(address string, handle func(conn Conn)) error Dial(address string) (Conn, error) // close the listener Close() }
ConnPool connection pool,address such as:"tcp://127.0.0.1:1111"
type ConnPoolMgr ¶
type ConnPoolMgr interface { RegConnPool(scheme string, c ConnPool) Listen(address string, handle func(conn Conn)) error Dial(address string) (Conn, error) // close the listener Close() }
ConnPoolMgr manager of connection pool,address such as:"tcp://127.0.0.1:1111"
type CryptoMgr ¶
type CryptoMgr interface { SetPrivKey(typ string, key []byte) error GetType() string Sign(data []byte) []byte Verify(typ string, data, sig, pubKey []byte) bool Register(k SignKey) GetPublic() []byte }
CryptoMgr crypto manager
type Event ¶
type Event interface { // encode by gob Reply(interface{}) error GetMessage() interface{} GetSession() Session GetPeerID() []byte }
Event interface of event
type IPlugin ¶
type IPlugin interface { // Callback for when the network starts listening for peers. Startup(net Network) // Callback for when the network stops listening for peers. Cleanup(net Network) // Callback for when an incoming message is received. Return true // if the plugin will intercept messages to be processed. Receive(e Event) error // RecInternalMsg receive internal message RecInternalMsg(InterMsg) error // Callback for when a peer connects to the network. PeerConnect(s Session) // Callback for when a peer disconnects from the network. PeerDisconnect(s Session) }
IPlugin is used to proxy callbacks to a particular Plugin instance.
type InterMsg ¶
type InterMsg interface { GetType() string GetMsg() interface{} }
InterMsg internal message
type Network ¶
type Network interface { // address: tcp://127.0.0.1:80 NewSession(address string) (Session, error) RegistPlugin(IPlugin) SendInternalMsg(InterMsg) GetAddress() string Close() }
Network interface of network manager
type Plugin ¶
type Plugin struct{}
Plugin is an abstract class which all plugins extend.
func (*Plugin) PeerConnect ¶
PeerConnect is called every time a Session is initialized and connected
func (*Plugin) PeerDisconnect ¶
PeerDisconnect is called every time a Session connection is closed
func (*Plugin) RecInternalMsg ¶
RecInternalMsg receive internal message