summaryrefslogtreecommitdiff
path: root/protocol
diff options
context:
space:
mode:
authorKeuin <[email protected]>2024-03-09 20:19:35 +0800
committerKeuin <[email protected]>2024-03-09 20:20:20 +0800
commitb933083d20b3db4a3d6a8134efe312eb6ff3d8e2 (patch)
tree2a86151c77b1eed1596b5f50ce824659e3c1fc22 /protocol
initial versionHEADmaster
Diffstat (limited to 'protocol')
-rw-r--r--protocol/handshake.go14
-rw-r--r--protocol/messages.go29
-rw-r--r--protocol/observe.go14
-rw-r--r--protocol/publish.go8
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"`
+}