Documentation
¶
Index ¶
- Constants
- Variables
- func Closer(left, right, target Address) (bool, error)
- func ProtocolWithCode(c int) multiaddr.Protocol
- func ProtocolWithName(s string) multiaddr.Protocol
- type Address
- type Addresses
- type ID
- type MultiAddress
- func (multiAddress MultiAddress) Address() Address
- func (multiAddress MultiAddress) Hash() []byte
- func (multiAddress MultiAddress) ID() ID
- func (multiAddress *MultiAddress) IsNil() bool
- func (multiAddress MultiAddress) MarshalJSON() ([]byte, error)
- func (multiAddress MultiAddress) String() string
- func (multiAddress *MultiAddress) UnmarshalJSON(data []byte) error
- func (multiAddress *MultiAddress) UnmarshalStringJSON(data []byte) error
- func (multiAddress MultiAddress) ValueForProtocol(code int) (string, error)
- type MultiAddresses
Constants ¶
const ( IP4Code = 0x0004 IP6Code = 0x0029 TCPCode = 0x0006 RepublicCode = 0x0065 )
Codes for extracting specific protocol values from a MultiAddress.
const AddressLength = 30
AddressLength is the number of bytes in an Address.
const IDLength = 20
IDLength is the number of bytes in an ID.
Variables ¶
var ( ErrFailToDecode = fmt.Errorf("fail to decode the string") ErrWrongAddressLength = fmt.Errorf("wrong address length") )
Errors returned by the package.
Functions ¶
func Closer ¶
Closer returns true if the left Address is closer to the target than the right Address, otherwise it returns false. In the case that both Addresses are equal distances from the target, it returns true.
func ProtocolWithCode ¶
ProtocolWithCode returns the Protocol description with the given code.
func ProtocolWithName ¶
ProtocolWithName returns the Protocol description with the given name.
Types ¶
type Address ¶
type Address string
An Address string is generated from an ID.
func (Address) MultiAddress ¶
func (address Address) MultiAddress() (MultiAddress, error)
MultiAddress returns the Republic multi-address of the Address. It can be appended with other MultiAddresses.
func (Address) SamePrefixLength ¶
SamePrefixLength returns the number of prefix bits that match with those of another Address, excluding the first 2 bytes.
type ID ¶
type ID []byte
An ID is a slice of 20 bytes that can be converted into an Address. It must always be exact 20 bytes.
type MultiAddress ¶
type MultiAddress struct {
Signature []byte
Nonce uint64
// contains filtered or unexported fields
}
MultiAddress is an alias.
func NewMultiAddressFromString ¶
func NewMultiAddressFromString(s string) (MultiAddress, error)
NewMultiAddressFromString parses and validates an input string. It returns a MultiAddress, or an error.
func (MultiAddress) Address ¶
func (multiAddress MultiAddress) Address() Address
Address returns the Republic address of a MultiAddress.
func (MultiAddress) Hash ¶
func (multiAddress MultiAddress) Hash() []byte
Hash returns the Keccak256 hash of a multiAddress. This hash is used to create signatures for a multiaddress.
func (MultiAddress) ID ¶
func (multiAddress MultiAddress) ID() ID
ID returns the Republic ID of a MultiAddress.
func (*MultiAddress) IsNil ¶
func (multiAddress *MultiAddress) IsNil() bool
IsNil checks if the multiAddress is nil.
func (MultiAddress) MarshalJSON ¶
func (multiAddress MultiAddress) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (MultiAddress) String ¶
func (multiAddress MultiAddress) String() string
String returns the MultiAddress as a plain string.
func (*MultiAddress) UnmarshalJSON ¶
func (multiAddress *MultiAddress) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
func (*MultiAddress) UnmarshalStringJSON ¶
func (multiAddress *MultiAddress) UnmarshalStringJSON(data []byte) error
UnmarshalStringJSON will unmarshal multi-addresses that are in string format to a standard multi-address struct.
func (MultiAddress) ValueForProtocol ¶
func (multiAddress MultiAddress) ValueForProtocol(code int) (string, error)
ValueForProtocol returns the value of the specific protocol in the MultiAddress