Add rpc request/response for handshake

This commit is contained in:
9seconds
2018-07-01 12:36:30 +03:00
parent 6253648356
commit b9ee1e1857
5 changed files with 112 additions and 7 deletions
+47
View File
@@ -0,0 +1,47 @@
package rpc
import "bytes"
const (
rpcHandshakeTagLength = 4
rpcHandshakeFlagsLength = 4
rpcHandshakeSenderPIDLength = 12
rpcHandshakePeerPIDLength = rpcHandshakeSenderPIDLength
rpcHandshakeRequestLength = rpcHandshakeTagLength + rpcHandshakeFlagsLength +
rpcHandshakeSenderPIDLength + rpcHandshakePeerPIDLength
)
var (
rpcHandshakeSenderPID [rpcHandshakeSenderPIDLength]byte
rpcHandshakePeerPID [rpcHandshakePeerPIDLength]byte
rpcHandshakeTag = [rpcHandshakeTagLength]byte{0xf5, 0xee, 0x82, 0x76}
rpcHandshakeFlags = [rpcHandshakeFlagsLength]byte{0x00, 0x00, 0x00, 0x00}
rpcHandshakeBuffer *bytes.Buffer
)
type RPCHandshakeRequest struct {
}
func (r *RPCHandshakeRequest) Bytes() *bytes.Buffer {
buf := &bytes.Buffer{}
buf.Grow(rpcHandshakeRequestLength)
buf.Write(rpcHandshakeTag[:])
buf.Write(rpcHandshakeFlags[:])
buf.Write(rpcHandshakeSenderPID[:])
buf.Write(rpcHandshakePeerPID[:])
return buf
}
func init() {
copy(rpcHandshakeSenderPID[:], "IPIPPRPDTIME")
copy(rpcHandshakePeerPID[:], "IPIPPRPDTIME")
}
func NewRPCHandshakeRequest() *RPCHandshakeRequest {
return &RPCHandshakeRequest{}
}