diff options
Diffstat (limited to 'protocol')
-rw-r--r-- | protocol/handshake.go | 14 | ||||
-rw-r--r-- | protocol/messages.go | 29 | ||||
-rw-r--r-- | protocol/observe.go | 14 | ||||
-rw-r--r-- | protocol/publish.go | 8 |
4 files changed, 65 insertions, 0 deletions
diff --git a/protocol/handshake.go b/protocol/handshake.go new file mode 100644 index 0000000..02e3f0d --- /dev/null +++ b/protocol/handshake.go @@ -0,0 +1,14 @@ +package protocol + +const ( + TokenHeader = "X-Observatory-Token" + ObserverIDHeader = "X-Observatory-Observer-ID" +) + +// ServerPushInfo is the first server->client packet, applying configs to observers +type ServerPushInfo struct { + Version uint64 `json:"server_push_info_version"` + Targets []Target `json:"targets"` +} + +const CurrentServerPushInfoVersion uint64 = 240308 diff --git a/protocol/messages.go b/protocol/messages.go new file mode 100644 index 0000000..d8f5697 --- /dev/null +++ b/protocol/messages.go @@ -0,0 +1,29 @@ +package protocol + +import ( + "encoding/json" + "time" +) + +type TimeStamp time.Time + +func (t *TimeStamp) UnmarshalJSON(data []byte) error { + var ts int64 + err := json.Unmarshal(data, &ts) + if err != nil { + return err + } + *t = TimeStamp(time.UnixMilli(ts)) + return nil +} + +func (t TimeStamp) MarshalJSON() ([]byte, error) { + return json.Marshal(time.Time(t).UnixMilli()) +} + +type Observation struct { + Time TimeStamp `json:"time"` + Target Target `json:"target"` + Online bool `json:"online"` + Latency uint32 `json:"latency"` +} diff --git a/protocol/observe.go b/protocol/observe.go new file mode 100644 index 0000000..48d052a --- /dev/null +++ b/protocol/observe.go @@ -0,0 +1,14 @@ +package protocol + +import ( + "fmt" +) + +type Target struct { + Host string `json:"host"` + Port uint16 `json:"port"` +} + +func (t Target) String() string { + return fmt.Sprintf("%s:%d", t.Host, t.Port) +} diff --git a/protocol/publish.go b/protocol/publish.go new file mode 100644 index 0000000..13e6ee1 --- /dev/null +++ b/protocol/publish.go @@ -0,0 +1,8 @@ +package protocol + +type TargetStats map[string][]SourcedObservation + +type SourcedObservation struct { + Observation + Source string `json:"source,omitempty"` +} |