mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 16:01:55 +03:00
Small refactorings of rpc package
This commit is contained in:
@@ -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{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user