Small refactorings of rpc package

This commit is contained in:
9seconds
2018-07-05 10:37:05 +03:00
parent a7eb29cc94
commit 0738631ef8
6 changed files with 91 additions and 128 deletions
+5 -30
View File
@@ -1,46 +1,21 @@
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}
)
import "bytes"
type RPCHandshakeRequest struct {
}
func (r *RPCHandshakeRequest) Bytes() []byte {
buf := &bytes.Buffer{}
buf.Grow(rpcHandshakeRequestLength)
buf.Write(rpcHandshakeTag[:])
buf.Write(rpcHandshakeFlags[:])
buf.Write(rpcHandshakeSenderPID[:])
buf.Write(rpcHandshakePeerPID[:])
buf.Write(RPCTagHandshake)
buf.Write(RPCHandshakeFlags)
buf.Write(RPCHandshakeSenderPID)
buf.Write(RPCHandshakePeerPID)
return buf.Bytes()
}
func init() {
copy(rpcHandshakeSenderPID[:], "IPIPPRPDTIME")
copy(rpcHandshakePeerPID[:], "IPIPPRPDTIME")
}
func NewRPCHandshakeRequest() *RPCHandshakeRequest {
return &RPCHandshakeRequest{}
}