meshcore: support for multibyte path hashes
This commit is contained in:
@@ -38,7 +38,14 @@ type Packet struct {
|
|||||||
// TransportCodes are set by transport route types.
|
// TransportCodes are set by transport route types.
|
||||||
TransportCodes []uint16 `json:"transport_codes,omitempty"`
|
TransportCodes []uint16 `json:"transport_codes,omitempty"`
|
||||||
|
|
||||||
// Path are repeater hashes.
|
// PathHashSize is the number of bytes per node in the path hash.
|
||||||
|
PathHashSize int `json:"path_hash_size"`
|
||||||
|
|
||||||
|
// PathHashCount is the number of nodes in the path hash.
|
||||||
|
PathHashCount int `json:"path_hash_count"`
|
||||||
|
|
||||||
|
// Path are repeater hashes. The first hash is the source node, the last hash is the destination node, and the middle hashes are repeaters.
|
||||||
|
// The path is empty for direct packets.
|
||||||
Path []byte `json:"path"`
|
Path []byte `json:"path"`
|
||||||
|
|
||||||
// Payload is the raw (encoded) payload.
|
// Payload is the raw (encoded) payload.
|
||||||
@@ -158,14 +165,21 @@ func (packet *Packet) UnmarshalBytes(data []byte) error {
|
|||||||
packet.TransportCodes = nil
|
packet.TransportCodes = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pathLength := int(data[offset])
|
var (
|
||||||
|
pathLength = int(data[offset])
|
||||||
|
pathHashSize = pathLength>>6 + 1
|
||||||
|
pathHashCount = pathLength & 63
|
||||||
|
pathByteLength = pathHashSize * pathHashCount
|
||||||
|
)
|
||||||
offset += 1
|
offset += 1
|
||||||
if pathLength > maxPathSize {
|
if pathByteLength > maxPathSize {
|
||||||
return fmt.Errorf("meshcore: path length %d exceeds maximum of %d", pathLength, maxPathSize)
|
return fmt.Errorf("meshcore: path length %d exceeds maximum of %d", pathByteLength, maxPathSize)
|
||||||
} else if pathLength > len(data[offset:]) {
|
} else if pathByteLength > len(data[offset:]) {
|
||||||
return io.ErrUnexpectedEOF
|
return io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
packet.Path = make([]byte, pathLength)
|
packet.Path = make([]byte, pathByteLength)
|
||||||
|
packet.PathHashSize = pathHashSize
|
||||||
|
packet.PathHashCount = pathHashCount
|
||||||
offset += copy(packet.Path, data[offset:])
|
offset += copy(packet.Path, data[offset:])
|
||||||
|
|
||||||
payloadLength := len(data[offset:])
|
payloadLength := len(data[offset:])
|
||||||
|
|||||||
Reference in New Issue
Block a user