5bdc115943
Overview of changes: - ClientIdentity has been removed, use discover.NodeID - Server now requires a private key to be set (instead of public key) - Server performs the encryption handshake before launching Peer - Dial logic takes peers from discover table - Encryption handshake code has been cleaned up a bit - baseProtocol is gone because we don't exchange peers anymore - Some parts of baseProtocol have moved into Peer instead
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package p2p
|
|
|
|
// Protocol represents a P2P subprotocol implementation.
|
|
type Protocol struct {
|
|
// Name should contain the official protocol name,
|
|
// often a three-letter word.
|
|
Name string
|
|
|
|
// Version should contain the version number of the protocol.
|
|
Version uint
|
|
|
|
// Length should contain the number of message codes used
|
|
// by the protocol.
|
|
Length uint64
|
|
|
|
// Run is called in a new groutine when the protocol has been
|
|
// negotiated with a peer. It should read and write messages from
|
|
// rw. The Payload for each message must be fully consumed.
|
|
//
|
|
// The peer connection is closed when Start returns. It should return
|
|
// any protocol-level error (such as an I/O error) that is
|
|
// encountered.
|
|
Run func(peer *Peer, rw MsgReadWriter) error
|
|
}
|
|
|
|
func (p Protocol) cap() Cap {
|
|
return Cap{p.Name, p.Version}
|
|
}
|
|
|
|
// Cap is the structure of a peer capability.
|
|
type Cap struct {
|
|
Name string
|
|
Version uint
|
|
}
|
|
|
|
func (cap Cap) RlpData() interface{} {
|
|
return []interface{}{cap.Name, cap.Version}
|
|
}
|
|
|
|
type capsByName []Cap
|
|
|
|
func (cs capsByName) Len() int { return len(cs) }
|
|
func (cs capsByName) Less(i, j int) bool { return cs[i].Name < cs[j].Name }
|
|
func (cs capsByName) Swap(i, j int) { cs[i], cs[j] = cs[j], cs[i] }
|