feat(wasm): update statistics tracking by adding announce metrics and updating packet handling
Some checks failed
Go Build Test / Build (freebsd, amd64) (pull_request) Successful in 9m24s
Bearer / scan (pull_request) Successful in 48s
Go Benchmarks / Run Benchmarks (pull_request) Successful in 1m10s
Go Build Test / Build (darwin, amd64) (pull_request) Successful in 38s
Go Build Test / Build (linux, amd64) (pull_request) Successful in 39s
Go Build Test / Build (windows, amd64) (pull_request) Successful in 38s
Go Build Test / Build (freebsd, arm) (pull_request) Successful in 41s
Go Build Test / Build (windows, arm) (pull_request) Successful in 38s
Go Build Test / Build (linux, arm) (pull_request) Successful in 40s
Go Build Test / Build (darwin, arm64) (pull_request) Successful in 33s
Go Build Test / Build (freebsd, arm64) (pull_request) Successful in 29s
Go Build Test / Build (linux, arm64) (pull_request) Successful in 45s
Go Build Test / Build (js, wasm) (pull_request) Failing after 41s
Go Build Test / Build (windows, arm64) (pull_request) Successful in 44s
Go Test Multi-Platform / Test (ubuntu-latest, arm64) (pull_request) Successful in 1m9s
Go Revive Lint / lint (pull_request) Successful in 1m5s
Run Gosec / tests (pull_request) Successful in 1m14s
Go Test Multi-Platform / Test (ubuntu-latest, amd64) (pull_request) Failing after 2m36s
Some checks failed
Go Build Test / Build (freebsd, amd64) (pull_request) Successful in 9m24s
Bearer / scan (pull_request) Successful in 48s
Go Benchmarks / Run Benchmarks (pull_request) Successful in 1m10s
Go Build Test / Build (darwin, amd64) (pull_request) Successful in 38s
Go Build Test / Build (linux, amd64) (pull_request) Successful in 39s
Go Build Test / Build (windows, amd64) (pull_request) Successful in 38s
Go Build Test / Build (freebsd, arm) (pull_request) Successful in 41s
Go Build Test / Build (windows, arm) (pull_request) Successful in 38s
Go Build Test / Build (linux, arm) (pull_request) Successful in 40s
Go Build Test / Build (darwin, arm64) (pull_request) Successful in 33s
Go Build Test / Build (freebsd, arm64) (pull_request) Successful in 29s
Go Build Test / Build (linux, arm64) (pull_request) Successful in 45s
Go Build Test / Build (js, wasm) (pull_request) Failing after 41s
Go Build Test / Build (windows, arm64) (pull_request) Successful in 44s
Go Test Multi-Platform / Test (ubuntu-latest, arm64) (pull_request) Successful in 1m9s
Go Revive Lint / lint (pull_request) Successful in 1m5s
Run Gosec / tests (pull_request) Successful in 1m14s
Go Test Multi-Platform / Test (ubuntu-latest, amd64) (pull_request) Failing after 2m36s
This commit is contained in:
@@ -24,10 +24,12 @@ var (
|
|||||||
reticulumDest *destination.Destination
|
reticulumDest *destination.Destination
|
||||||
reticulumIdentity *identity.Identity
|
reticulumIdentity *identity.Identity
|
||||||
stats = struct {
|
stats = struct {
|
||||||
packetsSent int
|
packetsSent int
|
||||||
packetsReceived int
|
packetsReceived int
|
||||||
bytesSent int
|
bytesSent int
|
||||||
bytesReceived int
|
bytesReceived int
|
||||||
|
announcesSent int
|
||||||
|
announcesReceived int
|
||||||
}{}
|
}{}
|
||||||
packetCallback js.Value
|
packetCallback js.Value
|
||||||
announceHandler js.Value
|
announceHandler js.Value
|
||||||
@@ -47,6 +49,7 @@ func RegisterJSFunctions() {
|
|||||||
"setPacketCallback": js.FuncOf(SetPacketCallback),
|
"setPacketCallback": js.FuncOf(SetPacketCallback),
|
||||||
"setAnnounceCallback": js.FuncOf(SetAnnounceCallback),
|
"setAnnounceCallback": js.FuncOf(SetAnnounceCallback),
|
||||||
"sendData": js.FuncOf(SendDataJS),
|
"sendData": js.FuncOf(SendDataJS),
|
||||||
|
"sendMessage": js.FuncOf(SendDataJS),
|
||||||
"announce": js.FuncOf(SendAnnounceJS),
|
"announce": js.FuncOf(SendAnnounceJS),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -100,11 +103,31 @@ func RequestPath(this js.Value, args []js.Value) interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetStats(this js.Value, args []js.Value) interface{} {
|
func GetStats(this js.Value, args []js.Value) interface{} {
|
||||||
|
if reticulumTransport != nil {
|
||||||
|
ifaces := reticulumTransport.GetInterfaces()
|
||||||
|
totalTxBytes := 0
|
||||||
|
totalRxBytes := 0
|
||||||
|
totalTxPackets := 0
|
||||||
|
totalRxPackets := 0
|
||||||
|
for _, iface := range ifaces {
|
||||||
|
totalTxBytes += int(iface.GetTxBytes())
|
||||||
|
totalRxBytes += int(iface.GetRxBytes())
|
||||||
|
totalTxPackets += int(iface.GetTxPackets())
|
||||||
|
totalRxPackets += int(iface.GetRxPackets())
|
||||||
|
}
|
||||||
|
stats.bytesSent = totalTxBytes
|
||||||
|
stats.bytesReceived = totalRxBytes
|
||||||
|
stats.packetsSent = totalTxPackets
|
||||||
|
stats.packetsReceived = totalRxPackets
|
||||||
|
}
|
||||||
|
|
||||||
return js.ValueOf(map[string]interface{}{
|
return js.ValueOf(map[string]interface{}{
|
||||||
"packetsSent": stats.packetsSent,
|
"packetsSent": stats.packetsSent,
|
||||||
"packetsReceived": stats.packetsReceived,
|
"packetsReceived": stats.packetsReceived,
|
||||||
"bytesSent": stats.bytesSent,
|
"bytesSent": stats.bytesSent,
|
||||||
"bytesReceived": stats.bytesReceived,
|
"bytesReceived": stats.bytesReceived,
|
||||||
|
"announcesSent": stats.announcesSent,
|
||||||
|
"announcesReceived": stats.announcesReceived,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +177,8 @@ func InitReticulum(this js.Value, args []js.Value) interface{} {
|
|||||||
|
|
||||||
cfg := common.DefaultConfig()
|
cfg := common.DefaultConfig()
|
||||||
t := transport.NewTransport(cfg)
|
t := transport.NewTransport(cfg)
|
||||||
|
// Ensure the global instance is set for internal RNS calls (like Announce)
|
||||||
|
transport.SetTransportInstance(t)
|
||||||
|
|
||||||
// Set transport identity to the same as the node identity for now in WASM
|
// Set transport identity to the same as the node identity for now in WASM
|
||||||
t.SetIdentity(id)
|
t.SetIdentity(id)
|
||||||
@@ -176,9 +201,6 @@ func InitReticulum(this js.Value, args []js.Value) interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dest.SetPacketCallback(func(data []byte, ni common.NetworkInterface) {
|
dest.SetPacketCallback(func(data []byte, ni common.NetworkInterface) {
|
||||||
stats.packetsReceived++
|
|
||||||
stats.bytesReceived += len(data)
|
|
||||||
|
|
||||||
if !packetCallback.IsUndefined() {
|
if !packetCallback.IsUndefined() {
|
||||||
// Convert bytes to JS Uint8Array for performance and compatibility
|
// Convert bytes to JS Uint8Array for performance and compatibility
|
||||||
uint8Array := js.Global().Get("Uint8Array").New(len(data))
|
uint8Array := js.Global().Get("Uint8Array").New(len(data))
|
||||||
@@ -198,12 +220,8 @@ func InitReticulum(this js.Value, args []js.Value) interface{} {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
wsInterface.SetPacketCallback(func(data []byte, ni common.NetworkInterface) {
|
// Wire the interface to the transport
|
||||||
msg := fmt.Sprintf("Received packet: %d bytes (type: 0x%02x)", len(data), data[0])
|
wsInterface.SetPacketCallback(t.HandlePacket)
|
||||||
js.Global().Call("log", msg, "success")
|
|
||||||
debug.Log(debug.DEBUG_INFO, "WASM received packet", "bytes", len(data), "type", fmt.Sprintf("0x%02x", data[0]))
|
|
||||||
t.HandlePacket(data, ni)
|
|
||||||
})
|
|
||||||
|
|
||||||
if err := t.RegisterInterface("wasm0", wsInterface); err != nil {
|
if err := t.RegisterInterface("wasm0", wsInterface); err != nil {
|
||||||
return js.ValueOf(map[string]interface{}{
|
return js.ValueOf(map[string]interface{}{
|
||||||
@@ -344,6 +362,8 @@ func (h *genericAnnounceHandler) ReceivePathResponses() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *genericAnnounceHandler) ReceivedAnnounce(destHash []byte, ident interface{}, appData []byte, hops uint8) error {
|
func (h *genericAnnounceHandler) ReceivedAnnounce(destHash []byte, ident interface{}, appData []byte, hops uint8) error {
|
||||||
|
debug.Log(debug.DEBUG_INFO, "WASM Announce Handler received announce", "dest", hex.EncodeToString(destHash), "hops", hops)
|
||||||
|
stats.announcesReceived++
|
||||||
if !announceHandler.IsUndefined() {
|
if !announceHandler.IsUndefined() {
|
||||||
hashStr := hex.EncodeToString(destHash)
|
hashStr := hex.EncodeToString(destHash)
|
||||||
announceHandler.Invoke(js.ValueOf(map[string]interface{}{
|
announceHandler.Invoke(js.ValueOf(map[string]interface{}{
|
||||||
@@ -437,9 +457,6 @@ func SendData(destHash []byte, data []byte) interface{} {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
stats.packetsSent++
|
|
||||||
stats.bytesSent += len(data)
|
|
||||||
|
|
||||||
return js.ValueOf(map[string]interface{}{
|
return js.ValueOf(map[string]interface{}{
|
||||||
"success": true,
|
"success": true,
|
||||||
})
|
})
|
||||||
@@ -475,6 +492,8 @@ func SendAnnounce(appData []byte) interface{} {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stats.announcesSent++
|
||||||
|
|
||||||
return js.ValueOf(map[string]interface{}{
|
return js.ValueOf(map[string]interface{}{
|
||||||
"success": true,
|
"success": true,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user