Cleanup incorrect or outdated code
This commit is contained in:
@@ -107,7 +107,7 @@ func NewReticulum(cfg *common.ReticulumConfig) (*Reticulum, error) {
|
|||||||
identity,
|
identity,
|
||||||
destination.IN,
|
destination.IN,
|
||||||
destination.SINGLE,
|
destination.SINGLE,
|
||||||
"Go-Client",
|
"nomadnetwork",
|
||||||
t,
|
t,
|
||||||
"node",
|
"node",
|
||||||
)
|
)
|
||||||
@@ -188,8 +188,11 @@ func NewReticulum(cfg *common.ReticulumConfig) (*Reticulum, error) {
|
|||||||
|
|
||||||
// Set packet callback
|
// Set packet callback
|
||||||
iface.SetPacketCallback(func(data []byte, ni common.NetworkInterface) {
|
iface.SetPacketCallback(func(data []byte, ni common.NetworkInterface) {
|
||||||
|
debugLog(3, "Packet callback called for interface %s, data len: %d", ni.GetName(), len(data))
|
||||||
if r.transport != nil {
|
if r.transport != nil {
|
||||||
r.transport.HandlePacket(data, ni)
|
r.transport.HandlePacket(data, ni)
|
||||||
|
} else {
|
||||||
|
debugLog(1, "Transport is nil in packet callback")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -415,7 +418,8 @@ func (r *Reticulum) Start() error {
|
|||||||
|
|
||||||
// Send initial announce
|
// Send initial announce
|
||||||
debugLog(2, "Sending initial announce")
|
debugLog(2, "Sending initial announce")
|
||||||
if err := r.destination.Announce(r.createNodeAppData()); err != nil {
|
nodeName := "Go-Client"
|
||||||
|
if err := r.destination.Announce([]byte(nodeName)); err != nil {
|
||||||
debugLog(1, "Failed to send initial announce: %v", err)
|
debugLog(1, "Failed to send initial announce: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,7 +430,7 @@ func (r *Reticulum) Start() error {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
debugLog(3, "Announcing destination...")
|
debugLog(3, "Announcing destination...")
|
||||||
err := r.destination.Announce(r.createNodeAppData())
|
err := r.destination.Announce([]byte(nodeName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debugLog(1, "Could not send announce: %v", err)
|
debugLog(1, "Could not send announce: %v", err)
|
||||||
}
|
}
|
||||||
@@ -490,84 +494,40 @@ func (h *AnnounceHandler) AspectFilter() []string {
|
|||||||
func (h *AnnounceHandler) ReceivedAnnounce(destHash []byte, id interface{}, appData []byte) error {
|
func (h *AnnounceHandler) ReceivedAnnounce(destHash []byte, id interface{}, appData []byte) error {
|
||||||
debugLog(DEBUG_INFO, "Received announce from %x", destHash)
|
debugLog(DEBUG_INFO, "Received announce from %x", destHash)
|
||||||
debugLog(DEBUG_PACKETS, "Raw announce data: %x", appData)
|
debugLog(DEBUG_PACKETS, "Raw announce data: %x", appData)
|
||||||
|
log.Printf("[DEBUG-3] MAIN HANDLER: Received announce from %x, appData len: %d", destHash, len(appData))
|
||||||
|
|
||||||
var isNode bool
|
var isNode bool
|
||||||
var nodeEnabled bool
|
var nodeEnabled bool
|
||||||
var nodeTimestamp int64
|
var nodeTimestamp int64
|
||||||
var nodeMaxSize int16
|
var nodeMaxSize int16
|
||||||
|
|
||||||
// Parse msgpack array
|
// Parse msgpack appData from transport announce format
|
||||||
if len(appData) > 0 {
|
if len(appData) > 0 {
|
||||||
if appData[0] == 0x92 {
|
// appData is msgpack array [name, customData]
|
||||||
// Format [name, ticket] for standard peers
|
if appData[0] == 0x92 { // array of 2 elements
|
||||||
debugLog(DEBUG_VERBOSE, "Received standard peer announce")
|
// Skip array header and first element (name)
|
||||||
isNode = false
|
pos := 1
|
||||||
var pos = 1
|
if pos < len(appData) && appData[pos] == 0xc4 { // bin 8
|
||||||
|
|
||||||
// Parse first element (NameBytes)
|
|
||||||
if pos+1 < len(appData) && appData[pos] == 0xc4 {
|
|
||||||
nameLen := int(appData[pos+1])
|
nameLen := int(appData[pos+1])
|
||||||
if pos+2+nameLen <= len(appData) {
|
pos += 2 + nameLen
|
||||||
nameBytes := appData[pos+2 : pos+2+nameLen]
|
if pos < len(appData) && appData[pos] == 0xc4 { // bin 8
|
||||||
name := string(nameBytes)
|
dataLen := int(appData[pos+1])
|
||||||
pos += 2 + nameLen
|
if pos+2+dataLen <= len(appData) {
|
||||||
debugLog(DEBUG_VERBOSE, "Peer name: %s (bytes: %x)", name, nameBytes)
|
customData := appData[pos+2 : pos+2+dataLen]
|
||||||
|
nodeName := string(customData)
|
||||||
// Parse second element (TicketValue)
|
log.Printf("[DEBUG-3] Parsed node name: %s", nodeName)
|
||||||
if pos < len(appData) {
|
debugLog(DEBUG_INFO, "Announced node: %s", nodeName)
|
||||||
ticketValue := appData[pos] // Assuming fixint for now
|
|
||||||
debugLog(DEBUG_VERBOSE, "Peer ticket value: %d", ticketValue)
|
|
||||||
} else {
|
|
||||||
debugLog(DEBUG_ERROR, "Could not parse ticket value from announce appData")
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
debugLog(DEBUG_ERROR, "Could not parse name bytes from announce appData")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debugLog(DEBUG_ERROR, "Announce appData name is not in expected bin 8 format")
|
|
||||||
}
|
|
||||||
} else if appData[0] == 0x93 {
|
|
||||||
// Format [enable, timestamp, maxsize] for nodes
|
|
||||||
debugLog(DEBUG_VERBOSE, "Received node announce")
|
|
||||||
isNode = true
|
|
||||||
var pos = 1
|
|
||||||
|
|
||||||
// Parse first element (Boolean enable/disable)
|
|
||||||
if pos < len(appData) {
|
|
||||||
if appData[pos] == 0xc3 {
|
|
||||||
nodeEnabled = true
|
|
||||||
} else if appData[pos] == 0xc2 {
|
|
||||||
nodeEnabled = false
|
|
||||||
} else {
|
|
||||||
debugLog(DEBUG_ERROR, "Unexpected format for node enabled status: %x", appData[pos])
|
|
||||||
}
|
|
||||||
pos++
|
|
||||||
debugLog(DEBUG_VERBOSE, "Node enabled: %v", nodeEnabled)
|
|
||||||
|
|
||||||
// Parse second element (Int32 timestamp)
|
|
||||||
if pos+4 < len(appData) && appData[pos] == 0xd2 {
|
|
||||||
pos++
|
|
||||||
timestamp := binary.BigEndian.Uint32(appData[pos : pos+4])
|
|
||||||
nodeTimestamp = int64(timestamp)
|
|
||||||
pos += 4
|
|
||||||
debugLog(DEBUG_VERBOSE, "Node timestamp: %d (%s)", timestamp, time.Unix(nodeTimestamp, 0))
|
|
||||||
|
|
||||||
// Parse third element (Int16 max transfer size)
|
|
||||||
if pos+2 < len(appData) && appData[pos] == 0xd1 {
|
|
||||||
pos++
|
|
||||||
maxSize := binary.BigEndian.Uint16(appData[pos : pos+2])
|
|
||||||
nodeMaxSize = int16(maxSize) // #nosec G115
|
|
||||||
debugLog(DEBUG_VERBOSE, "Node max transfer size: %d KB", nodeMaxSize)
|
|
||||||
} else {
|
|
||||||
debugLog(DEBUG_ERROR, "Could not parse max transfer size from node announce")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debugLog(DEBUG_ERROR, "Could not parse timestamp from node announce")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debugLog(DEBUG_VERBOSE, "Unknown announce data format: %x", appData)
|
// Fallback: treat as raw node name
|
||||||
|
nodeName := string(appData)
|
||||||
|
log.Printf("[DEBUG-3] Raw node name: %s", nodeName)
|
||||||
|
debugLog(DEBUG_INFO, "Announced node: %s", nodeName)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Printf("[DEBUG-3] No appData (empty announce)")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type assert and log identity details
|
// Type assert and log identity details
|
||||||
|
|||||||
Reference in New Issue
Block a user