Documentation ¶
Overview ¶
Package message provides insolar messaging protocol and serialization layer.
Message can be created with shortcut:
senderAddr, _ := node.NewAddress("127.0.0.1:1337") receiverAddr, _ := node.NewAddress("127.0.0.1:1338") sender := node.NewNode(senderAddr) receiver := node.NewNode(receiverAddr) msg := message.NewPingMessage(sender, receiver) // do something with message
Or with builder:
builder := message.NewBuilder() senderAddr, _ := node.NewAddress("127.0.0.1:1337") receiverAddr, _ := node.NewAddress("127.0.0.1:1338") sender := node.NewNode(senderAddr) receiver := node.NewNode(receiverAddr) msg := builder. Sender(sender). Receiver(receiver). Type(message.TypeFindNode). Request(&message.RequestDataFindNode{}). Build() // do something with message
Message may be serialized:
msg := &message.Message{} serialized, err := message.SerializeMessage(msg) if err != nil { panic(err.Error()) } fmt.Println(serialized)
And deserialized therefore:
var buffer bytes.Buffer // Fill buffer somewhere msg, err := message.DeserializeMessage(buffer) if err != nil { panic(err.Error()) } // do something with message
Index ¶
- Constants
- func SerializeMessage(q *Message) ([]byte, error)
- type Builder
- func (cb Builder) Build() (message *Message)
- func (cb Builder) Error(err error) Builder
- func (cb Builder) Receiver(node *node.Node) Builder
- func (cb Builder) Request(request interface{}) Builder
- func (cb Builder) Response(response interface{}) Builder
- func (cb Builder) Sender(node *node.Node) Builder
- func (cb Builder) Type(messageType messageType) Builder
- type CommandType
- type Message
- type RequestDataFindNode
- type RequestDataFindValue
- type RequestDataRPC
- type RequestDataStore
- type RequestID
- type RequestRelay
- type ResponseDataFindNode
- type ResponseDataFindValue
- type ResponseDataRPC
- type ResponseDataStore
- type ResponseRelay
Constants ¶
const ( // TypePing is message type for ping method. TypePing = messageType(iota + 1) // TypeStore is message type for store method. TypeStore // TypeFindNode is message type for FindNode method. TypeFindNode // TypeFindValue is message type for FindValue method. TypeFindValue // TypeRPC is message type for RPC method. TypeRPC // TypeRelay is message type for request target to be a relay TypeRelay )
const ( // Start - command start relay. Start = CommandType(iota + 1) // Stop - command stop relay. Stop )
Variables ¶
This section is empty.
Functions ¶
func SerializeMessage ¶
SerializeMessage converts message to byte slice.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder allows lazy building of messages. Each operation returns new copy of a builder.
type Message ¶
type Message struct { Sender *node.Node Receiver *node.Node Type messageType RequestID RequestID Data interface{} Error error IsResponse bool }
Message is DHT message object.
func DeserializeMessage ¶
DeserializeMessage reads message from io.Reader.
func NewPingMessage ¶
NewPingMessage can be used as a shortcut for creating ping messages instead of message Builder.
func NewRelayMessage ¶
func NewRelayMessage(command CommandType, sender, receiver *node.Node) *Message
NewRelayMessage uses for send a command to target node to make it as relay.
type RequestDataFindNode ¶
type RequestDataFindNode struct {
Target []byte
}
RequestDataFindNode is data for FindNode request.
type RequestDataFindValue ¶
type RequestDataFindValue struct {
Target []byte
}
RequestDataFindValue is data for FindValue request.
type RequestDataRPC ¶
RequestDataRPC is data for RPC request.
type RequestDataStore ¶
type RequestDataStore struct { Data []byte Publishing bool // Whether or not we are the original publisher. }
RequestDataStore is data for Store request.
type RequestRelay ¶
type RequestRelay struct {
Command CommandType
}
RequestRelay is data for relay request (commands: start/stop relay).
type ResponseDataFindNode ¶
ResponseDataFindNode is data for FindNode response.
type ResponseDataFindValue ¶
ResponseDataFindValue is data for FindValue response.
type ResponseDataRPC ¶
ResponseDataRPC is data for RPC response.
type ResponseDataStore ¶
type ResponseDataStore struct {
Success bool
}
ResponseDataStore is data for Store response.
type ResponseRelay ¶
ResponseRelay is data for relay request response