2019-02-22 09:23:14 +00:00
|
|
|
package gun
|
|
|
|
|
2019-02-22 19:51:50 +00:00
|
|
|
import "encoding/json"
|
|
|
|
|
2019-02-26 21:59:44 +00:00
|
|
|
// Message is the JSON-encodable message that Gun peers send to each other.
|
2019-02-22 09:23:14 +00:00
|
|
|
type Message struct {
|
2019-02-22 19:51:50 +00:00
|
|
|
Ack string `json:"@,omitempty"`
|
|
|
|
ID string `json:"#,omitempty"`
|
|
|
|
To string `json:"><,omitempty"`
|
|
|
|
Hash json.Number `json:"##,omitempty"`
|
2019-02-22 09:23:14 +00:00
|
|
|
How string `json:"how,omitempty"`
|
|
|
|
Get *MessageGetRequest `json:"get,omitempty"`
|
|
|
|
Put map[string]*Node `json:"put,omitempty"`
|
|
|
|
DAM string `json:"dam,omitempty"`
|
|
|
|
PID string `json:"pid,omitempty"`
|
2019-02-25 04:23:15 +00:00
|
|
|
OK int `json:"ok,omitempty"`
|
|
|
|
Err string `json:"err,omitempty"`
|
2019-02-22 09:23:14 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 21:59:44 +00:00
|
|
|
// MessageGetRequest is the format for Message.Get.
|
2019-02-22 09:23:14 +00:00
|
|
|
type MessageGetRequest struct {
|
|
|
|
Soul string `json:"#,omitempty"`
|
|
|
|
Field string `json:".,omitempty"`
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:28:19 +00:00
|
|
|
type messageReceived struct {
|
2019-02-22 09:23:14 +00:00
|
|
|
*Message
|
2019-02-26 21:59:44 +00:00
|
|
|
peer *Peer
|
|
|
|
// storedPuts are the souls and their fields that have been stored by
|
|
|
|
// another part of the code. This is useful if the main instance stores
|
|
|
|
// something it sees, there's no need for the message listener to do so as
|
|
|
|
// well.
|
2019-02-26 07:10:13 +00:00
|
|
|
storedPuts map[string][]string
|
2019-02-22 09:23:14 +00:00
|
|
|
}
|