Introduce Channel/Overlay Mappings #549

Merged
sarah merged 4 commits from overlays into master 2024-02-11 23:11:00 +00:00
Owner
  • Map channel 7 to ephemeral / no ack
  • Create model methods
  • Introduce optional latency measurements into Cwtch
- Map channel 7 to ephemeral / no ack - Create model methods - Introduce optional latency measurements into Cwtch
dan was assigned by sarah 2024-02-11 20:15:54 +00:00
sarah added 1 commit 2024-02-11 20:15:55 +00:00
continuous-integration/drone/pr Build is failing Details
792e79dceb
Introduce Channel/Overlay Mappings
- Map channel 7 to ephemeral / no ack
- Create model methods
- Introduce optional latency measurements into Cwtch
Member
Drone Build Status: failure https://build.openprivacy.ca/cwtch.im/cwtch/313
dan reviewed 2024-02-11 21:46:25 +00:00
model/overlay.go Outdated
@ -6,1 +10,4 @@
Data string `json:"d"`
// when the data was assembled
SendTime time.Time `json:"s,omitempty"`
Owner

bad news

https://stackoverflow.com/questions/32643815/json-omitempty-with-time-time-field

The omitempty tag option does not work with time.Time as it is a struct. There is a "zero" value for structs, but that is a struct value where all fields have their zero values. This is a "valid" value, so it is not treated as "empty".

But by simply changing it to a pointer: *time.Time, it will work 

confirmed with a quick test

package main

import (
        "time"
        "encoding/json"
        "fmt"
)

type TimeDemo struct {
        Date1 time.Time `json:"s,omitempty"`
        Date2 time.Time `json:"t,omitempty"`
        Date3 time.Time `json:"r,omitempty"`
}


func main() {
        dates := TimeDemo{ Date1: time.Now().UTC() }

        datesJson, _ := json.Marshal(dates)

        fmt.Printf("%v => %v\n", dates, string(datesJson))

        var dates2 TimeDemo 
        json.Unmarshal(datesJson, &dates2)

        fmt.Printf("=> %v\n", dates2)

}

and

> ./timedemo
{2024-02-11 21:44:07.01793423 +0000 UTC 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC} => {"s":"2024-02-11T21:44:07.01793423Z","t":"0001-01-01T00:00:00Z","r":"0001-01-01T00:00:00Z"}
=> {2024-02-11 21:44:07.01793423 +0000 UTC 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC}

we don't want to be padding our messages with 3 time stamps one only filled on receipt

bad news https://stackoverflow.com/questions/32643815/json-omitempty-with-time-time-field ``` The omitempty tag option does not work with time.Time as it is a struct. There is a "zero" value for structs, but that is a struct value where all fields have their zero values. This is a "valid" value, so it is not treated as "empty". But by simply changing it to a pointer: *time.Time, it will work ``` confirmed with a quick test ```go package main import ( "time" "encoding/json" "fmt" ) type TimeDemo struct { Date1 time.Time `json:"s,omitempty"` Date2 time.Time `json:"t,omitempty"` Date3 time.Time `json:"r,omitempty"` } func main() { dates := TimeDemo{ Date1: time.Now().UTC() } datesJson, _ := json.Marshal(dates) fmt.Printf("%v => %v\n", dates, string(datesJson)) var dates2 TimeDemo json.Unmarshal(datesJson, &dates2) fmt.Printf("=> %v\n", dates2) } ``` and ``` > ./timedemo {2024-02-11 21:44:07.01793423 +0000 UTC 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC} => {"s":"2024-02-11T21:44:07.01793423Z","t":"0001-01-01T00:00:00Z","r":"0001-01-01T00:00:00Z"} => {2024-02-11 21:44:07.01793423 +0000 UTC 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC} ``` we don't want to be padding our messages with 3 time stamps one only filled on receipt
sarah marked this conversation as resolved
sarah added 1 commit 2024-02-11 21:56:30 +00:00
continuous-integration/drone/pr Build is pending Details
3124f7b7c4
MessageOverlay time to pointer
dan reviewed 2024-02-11 22:30:31 +00:00
@ -148,6 +158,15 @@ func (pa *PeerApp) SendMessage(message model2.PeerMessage) error {
var serialized []byte
var err error
if cm, err := model.DeserializeMessage(string(message.Data)); err == nil {
Owner

if cm, err := model.DeserializeMessage(string(message.Data)); err == nil && cm != nil {

then delete if below

`if cm, err := model.DeserializeMessage(string(message.Data)); err == nil && cm != nil { ` then delete if below
dan marked this conversation as resolved
dan reviewed 2024-02-11 22:31:01 +00:00
@ -133,6 +135,14 @@ func (pa *PeerApp) listen() {
pa.version.Store(Version2)
}
} else {
if cm, err := model.DeserializeMessage(string(packet.Data)); err == nil {
Owner

if cm, err := model.DeserializeMessage(string(packet.Data)); err == nil && cm != nil {

and delete if below

`if cm, err := model.DeserializeMessage(string(packet.Data)); err == nil && cm != nil {` and delete if below
dan marked this conversation as resolved
dan reviewed 2024-02-11 22:33:52 +00:00
@ -443,0 +438,4 @@
// check if we should store this message locally...
if cm, err := model.DeserializeMessage(message); err == nil {
if cm.Overlay < 1024 || cm.Overlay&0x7 != 0x7 {
Owner

whats up with < 1024 and not 7?

your last pr had things partitioned along 0x300 i believe?

can we make these some constants

whats up with < 1024 and not 7? your last pr had things partitioned along 0x300 i believe? can we make these some constants
dan marked this conversation as resolved
sarah added 1 commit 2024-02-11 22:44:32 +00:00
continuous-integration/drone/pr Build is pending Details
1a034953df
Util Functions for MW
sarah added 1 commit 2024-02-11 22:45:22 +00:00
continuous-integration/drone/pr Build is pending Details
826ac40a5c
Stream check in engine
dan approved these changes 2024-02-11 23:06:45 +00:00
sarah merged commit 0907af57d5 into master 2024-02-11 23:11:00 +00:00
Sign in to join this conversation.
No description provided.