2022-09-12 08:31:02 +00:00
|
|
|
// Package router_identity implements the I2P RouterIdentity common data structure
|
2022-07-11 23:41:58 -04:00
|
|
|
package router_identity
|
2016-02-01 01:56:10 -08:00
|
|
|
|
|
|
|
import (
|
2022-05-22 19:59:20 -04:00
|
|
|
. "github.com/go-i2p/go-i2p/lib/common/keys_and_cert"
|
2024-10-18 14:27:41 -04:00
|
|
|
"github.com/go-i2p/go-i2p/lib/util/logger"
|
|
|
|
"github.com/sirupsen/logrus"
|
2016-02-01 01:56:10 -08:00
|
|
|
)
|
|
|
|
|
2024-10-18 14:27:41 -04:00
|
|
|
var log = logger.GetLogger()
|
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
/*
|
|
|
|
[RouterIdentity]
|
|
|
|
Accurate for version 0.9.49
|
2016-02-01 01:56:10 -08:00
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
Description
|
|
|
|
Defines the way to uniquely identify a particular router
|
2016-02-01 01:56:10 -08:00
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
Contents
|
|
|
|
Identical to KeysAndCert.
|
|
|
|
*/
|
2016-02-01 01:56:10 -08:00
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
// RouterIdentity is the represenation of an I2P RouterIdentity.
|
|
|
|
//
|
|
|
|
// https://geti2p.net/spec/common-structures#routeridentity
|
|
|
|
type RouterIdentity struct {
|
2024-10-03 21:31:54 -04:00
|
|
|
KeysAndCert
|
2016-02-01 01:56:10 -08:00
|
|
|
}
|
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
// ReadRouterIdentity returns RouterIdentity from a []byte.
|
|
|
|
// The remaining bytes after the specified length are also returned.
|
|
|
|
// Returns a list of errors that occurred during parsing.
|
2016-02-15 00:34:29 -08:00
|
|
|
func ReadRouterIdentity(data []byte) (router_identity RouterIdentity, remainder []byte, err error) {
|
2024-10-18 14:27:41 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"input_length": len(data),
|
|
|
|
}).Debug("Reading RouterIdentity from data")
|
2024-10-03 21:31:54 -04:00
|
|
|
keys_and_cert, remainder, err := ReadKeysAndCert(data)
|
2024-10-18 14:27:41 -04:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("Failed to read KeysAndCert for RouterIdentity")
|
|
|
|
return
|
|
|
|
}
|
2022-05-09 20:43:24 -04:00
|
|
|
router_identity = RouterIdentity{
|
2022-09-12 08:31:02 +00:00
|
|
|
keys_and_cert,
|
|
|
|
}
|
2024-10-18 14:27:41 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"remainder_length": len(remainder),
|
|
|
|
}).Debug("Successfully read RouterIdentity")
|
2022-05-09 20:43:24 -04:00
|
|
|
return
|
|
|
|
}
|