2026-02-20 19:34:36 +00:00
|
|
|
// Copyright (c) 2017-2026 Lethean (https://lt.hn)
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the European Union Public Licence (EUPL) version 1.2.
|
|
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
|
|
|
|
package p2p
|
|
|
|
|
|
2026-03-22 01:49:26 +00:00
|
|
|
import "dappco.re/go/core/p2p/node/levin"
|
2026-02-20 19:34:36 +00:00
|
|
|
|
|
|
|
|
// EncodePingRequest returns an encoded empty ping request payload.
|
|
|
|
|
func EncodePingRequest() ([]byte, error) {
|
|
|
|
|
return levin.EncodeStorage(levin.Section{})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DecodePingResponse parses a ping response payload.
|
|
|
|
|
func DecodePingResponse(data []byte) (status string, peerID uint64, err error) {
|
|
|
|
|
s, err := levin.DecodeStorage(data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", 0, err
|
|
|
|
|
}
|
|
|
|
|
if v, ok := s["status"]; ok {
|
|
|
|
|
blob, e := v.AsString()
|
|
|
|
|
if e != nil {
|
|
|
|
|
return "", 0, e
|
|
|
|
|
}
|
|
|
|
|
status = string(blob)
|
|
|
|
|
}
|
|
|
|
|
if v, ok := s["peer_id"]; ok {
|
|
|
|
|
peerID, err = v.AsUint64()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", 0, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return status, peerID, nil
|
|
|
|
|
}
|