Documentation ¶
Index ¶
- Variables
- func DecodeToPeerId(idEncoded string) ([]byte, error)
- func EncodePeerId(id []byte) string
- func MarshalRecord(record *proto.NodeRecord) ([]byte, error)
- func NewRecord(ipv4 string, port int) (*proto.NodeRecord, crypto.PrivateKey, error)
- func NewRecordWithOptions(key crypto.PrivateKey, options ...Option) (*proto.NodeRecord, error)
- func NewRecordWithPrivateKey(privateKey crypto.PrivateKey, ipv4 string, port int) (*proto.NodeRecord, error)
- func Pretty(record *proto.NodeRecord) string
- func SignNodeRecord(privateKey crypto.PrivateKey, record *proto.NodeRecord) (*proto.NodeRecord, error)
- func UnMarshalRecord(b []byte) (*proto.NodeRecord, error)
- func ValidateId(id []byte) bool
- func ValidateIp(ip string) bool
- func ValidatePort(port int) bool
- func VerifyRecord(record *proto.NodeRecord) (bool, error)
- func VerifyRecordWithPubKey(pubKey crypto.PublicKey, record *proto.NodeRecord) (bool, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidPeerId = errors.New("invalid peer id") ErrInvalidSignature = errors.New("invalid signature") ErrInvalidPubKey = errors.New("invalid pub key") ErrMarshal = errors.New("error while marshalling pub key") ErrPrelimCheck = errors.New("mandatory fields missing") ErrInvalidIp = errors.New("invalid ip address") ErrInvalidPort = errors.New("invalid port") )
Functions ¶
func DecodeToPeerId ¶ added in v0.0.3
DecodeToPeerId decodes the peer id from string to byte array
func EncodePeerId ¶ added in v0.0.3
EncodePeerId encodes the peer id to a string
func MarshalRecord ¶
func MarshalRecord(record *proto.NodeRecord) ([]byte, error)
MarshalRecord marshals a record for transport
func NewRecord ¶
func NewRecord(ipv4 string, port int) (*proto.NodeRecord, crypto.PrivateKey, error)
NewRecord generates a new node record, with an autogenerated private key.
func NewRecordWithOptions ¶ added in v0.0.3
func NewRecordWithOptions(key crypto.PrivateKey, options ...Option) (*proto.NodeRecord, error)
NewRecordWithOptions returns a new record with the specified options.
func NewRecordWithPrivateKey ¶
func NewRecordWithPrivateKey(privateKey crypto.PrivateKey, ipv4 string, port int) (*proto.NodeRecord, error)
NewRecordWithPrivateKey creates a new record with the specified parameters.
func Pretty ¶
func Pretty(record *proto.NodeRecord) string
Pretty just returns a human readable string
func SignNodeRecord ¶
func SignNodeRecord(privateKey crypto.PrivateKey, record *proto.NodeRecord) (*proto.NodeRecord, error)
SignNodeRecord signs a node record.
func UnMarshalRecord ¶
func UnMarshalRecord(b []byte) (*proto.NodeRecord, error)
UnMarshalRecord unmarshalls the record.
func ValidateId ¶ added in v0.0.3
ValidateId validates the length of the Id. For most operations, we worry only about the length Encoding and other verifications should already be done as a part of VerifyRecord
func ValidateIp ¶ added in v0.0.3
ValidateIp returns if the given ip string is valid
func ValidatePort ¶ added in v0.0.3
ValidatePort returns if the given port is valid or not For validation, ephemeral ports are not allowed.
func VerifyRecord ¶
func VerifyRecord(record *proto.NodeRecord) (bool, error)
VerifyRecord verifies the given record.
func VerifyRecordWithPubKey ¶ added in v0.0.2
VerifyRecordWithPubKey verifies the signature of the node record.
Types ¶
type Option ¶ added in v0.0.3
type Option func(record *proto.NodeRecord) error
func WithPrivateKey ¶ added in v0.0.3
func WithPrivateKey(privateKey crypto.PrivateKey) Option
WithPrivateKey returns an option for adding "pubKey" & ID fields. It derives the public key & ID from the Specified private key
func WithRelays ¶ added in v0.0.3
func WithRelays(relays ...*proto.NodeRecord) Option
WithRelays returns an option that could be used for adding relays