bmwire

package module
v0.0.0-...-4a9ceef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2015 License: ISC Imports: 15 Imported by: 0

README

bmwire

Wire protocol for bitmessage written in Go

Documentation

Index

Constants

View Source
const (
	CmdVersion = "version"
	CmdVerAck  = "verack"
	CmdGetAddr = "getaddr"
	CmdAddr    = "addr"
	CmdInv     = "inv"
	CmdGetData = "getdata"
	CmdObject  = "object"
)

Commands used in bitmessage message headers which describe the type of message.

View Source
const (
	SimplePubKeyVersion    = 2
	ExtendedPubKeyVersion  = 3
	EncryptedPubKeyVersion = 4
)
View Source
const CommandSize = 12

CommandSize is the fixed size of all commands in the common bitmessage message header. Shorter commands must be zero padded.

View Source
const DefaultUserAgent = "/bmwire:0.2.0/"

DefaultUserAgent for bmwire.in the stack

View Source
const HashSize = 32

Size of array used to store sha hashes. See ShaHash.

View Source
const MaxAddrPerMsg = 1000

MaxAddrPerMsg is the maximum number of addresses that can be in a single bitmessage addr message (MsgAddr).

View Source
const MaxHashStringSize = HashSize * 2

MaxHashStringSize is the maximum length of a ShaHash hash string.

View Source
const (
	// MaxInvPerMsg is the maximum number of inventory vectors that can be in a
	// single bitmessage inv message.
	MaxInvPerMsg = 50000
)
View Source
const MaxMessagePayload = (1024 * 1024 * 32) // 32MB

MaxMessagePayload is the maximum bytes a message can be regardless of other individual limits imposed by messages themselves.

View Source
const MaxPubKeyStringSize = PubKeySize * 2

MaxHashStringSize is the maximum length of a Ripe hash string.

View Source
const MaxRipeHashStringSize = RipeHashSize * 2

MaxHashStringSize is the maximum length of a Ripe hash string.

View Source
const MaxUserAgentLen = 2000

MaxUserAgentLen is the maximum allowed length for the user agent field in a version message (MsgVersion).

View Source
const MaxVarIntPayload = 9

Maximum payload size for a variable length integer.

View Source
const MessageHeaderSize = 24

MessageHeaderSize is the number of bytes in a bitmessage message header. Bitmessage network (magic) 4 bytes + command 12 bytes + payload length 4 bytes + checksum 4 bytes.

View Source
const (
	// ProtocolVersion is the latest protocol version this package supports.
	ProtocolVersion uint32 = 3
)
View Source
const PubKeySize = 64

Size of array used to store Public Keys

View Source
const RipeHashSize = 20

Size of array used to store ripe hashes.

View Source
const (
	// Starting in version 4, Ripe is derived from the tag and not
	// sent directly
	TagBasedRipeVersion = 4
)

Variables

View Source
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)

ErrHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.

View Source
var ErrInvalidNetAddr = errors.New("provided net.Addr is not a net.TCPAddr")

ErrInvalidNetAddr describes an error that indicates the caller didn't specify a TCP address as required.

View Source
var ErrPubKeyStrSize = fmt.Errorf("max hash string length is %v bytes", MaxPubKeyStringSize)

ErrPubKeyStrSize describes an error that indicates the caller specified a hash string that has too many characters.

View Source
var ErrRipeHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxRipeHashStringSize)

ErrRipeHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.

Functions

func RandomUint64

func RandomUint64() (uint64, error)

RandomUint64 returns a cryptographically random uint64 value.

func Sha512

func Sha512(b []byte) []byte

Sha512 returns the sha256 of the bytes

func VarIntSerializeSize

func VarIntSerializeSize(val uint64) int

VarIntSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.

func WriteMessage

func WriteMessage(w io.Writer, msg Message, bmnet BitmessageNet) error

WriteMessage writes a bitmessage Message to w including the necessary header information. This function is the same as WriteMessageN except it doesn't doesn't return the number of bytes written. This function is mainly provided for backwards compatibility with the original API, but it's also useful for callers that don't care about byte counts.

func WriteMessageN

func WriteMessageN(w io.Writer, msg Message, bmnet BitmessageNet) (int, error)

WriteMessageN writes a bitmessage Message to w including the necessary header information and returns the number of bytes written. This function is the same as WriteMessage except it also returns the number of bytes written.

Types

type BitmessageNet

type BitmessageNet uint32

BitmessageNet represents which bitmessage network a message belongs to.

const (
	// MainNet represents the main bitmessage network.
	MainNet BitmessageNet = 0xe9beb4d9
)

Constants used to indicate the message bitmessage network. They can also be used to seek to the next message when a stream's state is unknown, but this package does not provide that functionality since it's generally a better idea to simply disconnect clients that are misbehaving over TCP.

func (BitmessageNet) String

func (n BitmessageNet) String() string

String returns the BitmessageNet in human-readable form.

type InvVect

type InvVect struct {
	Hash ShaHash // Hash of the data
}

InvVect defines a bitmessage inventory vector which is used to describe data, as specified by the Type field, that a peer wants, has, or does not have to another peer.

func NewInvVect

func NewInvVect(hash *ShaHash) *InvVect

NewInvVect returns a new InvVect using the provided type and hash.

type Message

type Message interface {
	Decode(io.Reader) error
	Encode(io.Writer) error
	Command() string
	MaxPayloadLength() uint32
}

Message is an interface that describes a bitmessage message. A type that implements Message has complete control over the representation of its data and may therefore contain additional or fewer fields than those which are used directly in the protocol encoded message.

func ReadMessage

func ReadMessage(r io.Reader, bmnet BitmessageNet) (Message, []byte, error)

ReadMessage reads, validates, and parses the next bitmessage Message from r for the provided protocol version and bitmessage network. It returns the parsed Message and raw bytes which comprise the message. This function only differs from ReadMessageN in that it doesn't return the number of bytes read. This function is mainly provided for backwards compatibility with the original API, but it's also useful for callers that don't care about byte counts.

func ReadMessageN

func ReadMessageN(r io.Reader, bmnet BitmessageNet) (int, Message, []byte, error)

ReadMessageN reads, validates, and parses the next bitmessage Message from r for the provided protocol version and bitmessage network. It returns the number of bytes read in addition to the parsed Message and raw bytes which comprise the message. This function is the same as ReadMessage except it also returns the number of bytes read.

type MessageError

type MessageError struct {
	Func        string // Function name
	Description string // Human readable description of the issue
}

MessageError describes an issue with a message. An example of some potential issues are messages from the wrong bitmessage network, invalid commands, mismatched checksums, and exceeding max payloads.

This provides a mechanism for the caller to type assert the error to differentiate between general io errors such as io.EOF and issues that resulted from malformed messages.

func (*MessageError) Error

func (e *MessageError) Error() string

Error satisfies the error interface and prints human-readable errors.

type MsgAddr

type MsgAddr struct {
	AddrList []*NetAddress
}

MsgAddr implements the Message interface and represents a bitmessage addr message. It is used to provide a list of known active peers on the network. An active peer is considered one that has transmitted a message within the last 3 hours. Nodes which have not transmitted in that time frame should be forgotten. Each message is limited to a maximum number of addresses, which is currently 1000. As a result, multiple messages must be used to relay the full list.

Use the AddAddress function to build up the list of known addresses when sending an addr message to another peer.

func NewMsgAddr

func NewMsgAddr() *MsgAddr

NewMsgAddr returns a new bitmessage addr message that conforms to the Message interface. See MsgAddr for details.

func (*MsgAddr) AddAddress

func (msg *MsgAddr) AddAddress(na *NetAddress) error

AddAddress adds a known active peer to the message.

func (*MsgAddr) AddAddresses

func (msg *MsgAddr) AddAddresses(netAddrs ...*NetAddress) error

AddAddresses adds multiple known active peers to the message.

func (*MsgAddr) ClearAddresses

func (msg *MsgAddr) ClearAddresses()

ClearAddresses removes all addresses from the message.

func (*MsgAddr) Command

func (msg *MsgAddr) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgAddr) Decode

func (msg *MsgAddr) Decode(r io.Reader) error

Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgAddr) Encode

func (msg *MsgAddr) Encode(w io.Writer) error

Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.

func (*MsgAddr) MaxPayloadLength

func (msg *MsgAddr) MaxPayloadLength() uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgGetAddr

type MsgGetAddr struct{}

MsgGetAddr implements the Message interface and represents a bitmessage getaddr message. It is used to request a list of known active peers on the network from a peer to help identify potential nodes. The list is returned via one or more addr messages (MsgAddr).

This message has no payload.

func NewMsgGetAddr

func NewMsgGetAddr() *MsgGetAddr

NewMsgGetAddr returns a new bitmessage getaddr message that conforms to the Message interface. See MsgGetAddr for details.

func (*MsgGetAddr) Command

func (msg *MsgGetAddr) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgGetAddr) Decode

func (msg *MsgGetAddr) Decode(r io.Reader) error

Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgGetAddr) Encode

func (msg *MsgGetAddr) Encode(w io.Writer) error

Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.

func (*MsgGetAddr) MaxPayloadLength

func (msg *MsgGetAddr) MaxPayloadLength() uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgGetData

type MsgGetData struct {
	InvList []*InvVect
}

MsgGetData implements the Message interface and represents a bitmessage getdata message. It is used to request data such as blocks and transactions from another peer. It should be used in response to the inv (MsgInv) message to request the actual data referenced by each inventory vector the receiving peer doesn't already have. Each message is limited to a maximum number of inventory vectors, which is currently 50,000. As a result, multiple messages must be used to request larger amounts of data.

Use the AddInvVect function to build up the list of inventory vectors when sending a getdata message to another peer.

func NewMsgGetData

func NewMsgGetData() *MsgGetData

NewMsgGetData returns a new bitmessage getdata message that conforms to the Message interface. See MsgGetData for details.

func NewMsgGetDataSizeHint

func NewMsgGetDataSizeHint(sizeHint uint) *MsgGetData

NewMsgGetDataSizeHint returns a new bitmessage getdata message that conforms to the Message interface. See MsgGetData for details. This function differs from NewMsgGetData in that it allows a default allocation size for the backing array which houses the inventory vector list. This allows callers who know in advance how large the inventory list will grow to avoid the overhead of growing the internal backing array several times when appending large amounts of inventory vectors with AddInvVect. Note that the specified hint is just that - a hint that is used for the default allocation size. Adding more (or less) inventory vectors will still work properly. The size hint is limited to MaxInvPerMsg.

func (*MsgGetData) AddInvVect

func (msg *MsgGetData) AddInvVect(iv *InvVect) error

AddInvVect adds an inventory vector to the message.

func (*MsgGetData) Command

func (msg *MsgGetData) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgGetData) Decode

func (msg *MsgGetData) Decode(r io.Reader) error

Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgGetData) Encode

func (msg *MsgGetData) Encode(w io.Writer) error

Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.

func (*MsgGetData) MaxPayloadLength

func (msg *MsgGetData) MaxPayloadLength() uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgGetPubKey

type MsgGetPubKey struct {
	Nonce        uint64
	ExpiresTime  time.Time
	ObjectType   ObjectType
	Version      uint64
	StreamNumber uint64
	Ripe         *RipeHash
	Tag          *ShaHash
}

func NewMsgGetPubKey

func NewMsgGetPubKey(nonce uint64, expires time.Time, version, streamNumber uint64, ripe *RipeHash, tag *ShaHash) *MsgGetPubKey

NewMsgGetPubKey returns a new object message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func (*MsgGetPubKey) Command

func (msg *MsgGetPubKey) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgGetPubKey) Decode

func (msg *MsgGetPubKey) Decode(r io.Reader) error

Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgGetPubKey) Encode

func (msg *MsgGetPubKey) Encode(w io.Writer) error

Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.

func (*MsgGetPubKey) MaxPayloadLength

func (msg *MsgGetPubKey) MaxPayloadLength() uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

func (*MsgGetPubKey) String

func (msg *MsgGetPubKey) String() string

type MsgInv

type MsgInv struct {
	InvList []*InvVect
}

MsgInv implements the Message interface and represents a bitmessage inv message. It is used to advertise a peer's known data such as blocks and transactions through inventory vectors. It may be sent unsolicited to inform other peers of the data or in response to a getblocks message (MsgGetBlocks). Each message is limited to a maximum number of inventory vectors, which is currently 50,000.

Use the AddInvVect function to build up the list of inventory vectors when sending an inv message to another peer.

func NewMsgInv

func NewMsgInv() *MsgInv

NewMsgInv returns a new bitmessage inv message that conforms to the Message interface. See MsgInv for details.

func NewMsgInvSizeHint

func NewMsgInvSizeHint(sizeHint uint) *MsgInv

NewMsgInvSizeHint returns a new bitmessage inv message that conforms to the Message interface. See MsgInv for details. This function differs from NewMsgInv in that it allows a default allocation size for the backing array which houses the inventory vector list. This allows callers who know in advance how large the inventory list will grow to avoid the overhead of growing the internal backing array several times when appending large amounts of inventory vectors with AddInvVect. Note that the specified hint is just that - a hint that is used for the default allocation size. Adding more (or less) inventory vectors will still work properly. The size hint is limited to MaxInvPerMsg.

func (*MsgInv) AddInvVect

func (msg *MsgInv) AddInvVect(iv *InvVect) error

AddInvVect adds an inventory vector to the message.

func (*MsgInv) Command

func (msg *MsgInv) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgInv) Decode

func (msg *MsgInv) Decode(r io.Reader) error

Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgInv) Encode

func (msg *MsgInv) Encode(w io.Writer) error

Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.

func (*MsgInv) MaxPayloadLength

func (msg *MsgInv) MaxPayloadLength() uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgPubKey

type MsgPubKey struct {
	Nonce        uint64
	ExpiresTime  time.Time
	ObjectType   ObjectType
	Version      uint64
	StreamNumber uint64
	Behavior     uint32
	SigningKey   *PubKey
	EncryptKey   *PubKey
	NonceTrials  uint64
	ExtraBytes   uint64
	Signature    []byte
	Tag          *ShaHash
	Encrypted    []byte
}

func NewMsgPubKey

func NewMsgPubKey(nonce uint64, expires time.Time,
	version, streamNumber uint64, behavior uint32,
	signingKey, encryptKey *PubKey, nonceTrials, extraBytes uint64,
	signature []byte, tag *ShaHash, encrypted []byte) *MsgPubKey

NewMsgPubKey returns a new object message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func (*MsgPubKey) Command

func (msg *MsgPubKey) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgPubKey) Decode

func (msg *MsgPubKey) Decode(r io.Reader) error

Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgPubKey) Encode

func (msg *MsgPubKey) Encode(w io.Writer) error

Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.

func (*MsgPubKey) MaxPayloadLength

func (msg *MsgPubKey) MaxPayloadLength() uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

func (*MsgPubKey) String

func (msg *MsgPubKey) String() string

type MsgVerAck

type MsgVerAck struct{}

MsgVerAck defines a bitmessage verack message which is used for a peer to acknowledge a version message (MsgVersion) after it has used the information to negotiate parameters. It implements the Message interface.

This message has no payload.

func NewMsgVerAck

func NewMsgVerAck() *MsgVerAck

NewMsgVerAck returns a new bitmessage verack message that conforms to the Message interface.

func (*MsgVerAck) Command

func (msg *MsgVerAck) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgVerAck) Decode

func (msg *MsgVerAck) Decode(r io.Reader) error

Decode decodes r using the bitmessage protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgVerAck) Encode

func (msg *MsgVerAck) Encode(w io.Writer) error

Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.

func (*MsgVerAck) MaxPayloadLength

func (msg *MsgVerAck) MaxPayloadLength() uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type MsgVersion

type MsgVersion struct {
	// Version of the protocol the node is using.
	ProtocolVersion int32

	// Bitfield which identifies the enabled services.
	Services ServiceFlag

	// Time the message was generated.  This is encoded as an int64 on the bmwire.
	Timestamp time.Time

	// Address of the remote peer.
	AddrYou NetAddress

	// Address of the local peer.
	AddrMe NetAddress

	// Unique value associated with message that is used to detect self
	// connections.
	Nonce uint64

	// The user agent that generated messsage.  This is a encoded as a varString
	// on the bmwire.  This has a max length of MaxUserAgentLen.
	UserAgent string

	// The stream numbers of interest.
	StreamNumbers []uint64
}

MsgVersion implements the Message interface and represents a bitmessage version message. It is used for a peer to advertise itself as soon as an outbound connection is made. The remote peer then uses this information along with its own to negotiate. The remote peer must then respond with a version message of its own containing the negotiated values followed by a verack message (MsgVerAck). This exchange must take place before any further communication is allowed to proceed.

func NewMsgVersion

func NewMsgVersion(me *NetAddress, you *NetAddress, nonce uint64, streams []uint64) *MsgVersion

NewMsgVersion returns a new bitmessage version message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func NewMsgVersionFromConn

func NewMsgVersionFromConn(conn net.Conn, nonce uint64, streams []uint64) (*MsgVersion, error)

NewMsgVersionFromConn is a convenience function that extracts the remote and local address from conn and returns a new bitmessage version message that conforms to the Message interface. See NewMsgVersion.

func (*MsgVersion) AddService

func (msg *MsgVersion) AddService(service ServiceFlag)

AddService adds service as a supported service by the peer generating the message.

func (*MsgVersion) AddUserAgent

func (msg *MsgVersion) AddUserAgent(name string, version string,
	comments ...string) error

AddUserAgent adds a user agent to the user agent string for the version message. The version string is not defined to any strict format, although it is recommended to use the form "major.minor.revision" e.g. "2.6.41".

func (*MsgVersion) Command

func (msg *MsgVersion) Command() string

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgVersion) Decode

func (msg *MsgVersion) Decode(r io.Reader) error

Decode decodes r using the bitmessage protocol encoding into the receiver.

This is part of the Message interface implementation.

func (*MsgVersion) Encode

func (msg *MsgVersion) Encode(w io.Writer) error

Encode encodes the receiver to w using the bitmessage protocol encoding. This is part of the Message interface implementation.

func (*MsgVersion) HasService

func (msg *MsgVersion) HasService(service ServiceFlag) bool

HasService returns whether the specified service is supported by the peer that generated the message.

func (*MsgVersion) MaxPayloadLength

func (msg *MsgVersion) MaxPayloadLength() uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

type NetAddress

type NetAddress struct {
	// Last time the address was seen.  This is, unfortunately, encoded as a
	// uint32 on the bmwire.and therefore is limited to 2106.  This field is
	// not present in the bitmessage version message (MsgVersion) nor was it
	// added until protocol version >= NetAddressTimeVersion.
	Timestamp time.Time

	// Bitfield which identifies the services supported by the address.
	Services ServiceFlag

	// IP address of the peer.
	IP net.IP

	// Port the peer is using.  This is encoded in big endian on the wire
	// which differs from most everything else.
	Port uint16
}

NetAddress defines information about a peer on the network including the time it was last seen, the services it supports, its IP address, and port.

func NewNetAddress

func NewNetAddress(addr net.Addr, services ServiceFlag) (*NetAddress, error)

NewNetAddress returns a new NetAddress using the provided TCP address and supported services with defaults for the remaining fields.

Note that addr must be a net.TCPAddr. An ErrInvalidNetAddr is returned if it is not.

func NewNetAddressIPPort

func NewNetAddressIPPort(ip net.IP, port uint16, services ServiceFlag) *NetAddress

NewNetAddressIPPort returns a new NetAddress using the provided IP, port, and supported services with defaults for the remaining fields.

func (*NetAddress) AddService

func (na *NetAddress) AddService(service ServiceFlag)

AddService adds service as a supported service by the peer generating the message.

func (*NetAddress) HasService

func (na *NetAddress) HasService(service ServiceFlag) bool

HasService returns whether the specified service is supported by the address.

func (*NetAddress) SetAddress

func (na *NetAddress) SetAddress(ip net.IP, port uint16)

SetAddress is a convenience function to set the IP address and port in one call.

type ObjectType

type ObjectType uint32
const (
	ObjectTypeGetPubKey ObjectType = 0
	ObjectTypePubKey    ObjectType = 1
	ObjectTypeMsg       ObjectType = 2
	ObjectTypeBroadcast ObjectType = 3
)

type PubKey

type PubKey [PubKeySize]byte

PubKey is used in several of the bitmessage messages and common structures. It typically represents the double sha512 and ripemd160 of data.

func NewPubKey

func NewPubKey(newHash []byte) (*PubKey, error)

NewPubKey returns a new PubKey from a byte slice. An error is returned if the number of bytes passed in is not PubKeySize.

func NewPubKeyFromStr

func NewPubKeyFromStr(hash string) (*PubKey, error)

NewPubKeyFromStr creates a PubKey from a hash string. The string should be the hexadecimal string of a byte hash, but any missing characters result in zero padding at the end of the PubKey.

func (*PubKey) Bytes

func (hash *PubKey) Bytes() []byte

Bytes returns the bytes which represent the hash as a byte slice.

func (*PubKey) IsEqual

func (hash *PubKey) IsEqual(target *PubKey) bool

IsEqual returns true if target is the same as hash.

func (*PubKey) SetBytes

func (hash *PubKey) SetBytes(newHash []byte) error

SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not PubKeySize.

func (PubKey) String

func (hash PubKey) String() string

String returns the PubKey as the hexadecimal string of the byte-reversed hash.

type RipeHash

type RipeHash [RipeHashSize]byte

RipeHash is used in several of the bitmessage messages and common structures. It typically represents the double sha512 and ripemd160 of data.

func NewRipeHash

func NewRipeHash(newHash []byte) (*RipeHash, error)

NewRipeHash returns a new RipeHash from a byte slice. An error is returned if the number of bytes passed in is not RipeHashSize.

func NewRipeHashFromStr

func NewRipeHashFromStr(hash string) (*RipeHash, error)

NewRipeHashFromStr creates a RipeHash from a hash string. The string should be the hexadecimal string of a byte hash, but any missing characters result in zero padding at the end of the RipeHash.

func (*RipeHash) Bytes

func (hash *RipeHash) Bytes() []byte

Bytes returns the bytes which represent the hash as a byte slice.

func (*RipeHash) IsEqual

func (hash *RipeHash) IsEqual(target *RipeHash) bool

IsEqual returns true if target is the same as hash.

func (*RipeHash) SetBytes

func (hash *RipeHash) SetBytes(newHash []byte) error

SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not RipeHashSize.

func (RipeHash) String

func (hash RipeHash) String() string

String returns the RipeHash as the hexadecimal string of the byte-reversed hash.

type ServiceFlag

type ServiceFlag uint64

ServiceFlag identifies services supported by a bitmessage peer.

const (
	// SFNodeNetwork is a flag used to indicate a peer is a full node.
	SFNodeNetwork ServiceFlag = 1 << iota
)

func (ServiceFlag) String

func (f ServiceFlag) String() string

String returns the ServiceFlag in human-readable form.

type ShaHash

type ShaHash [HashSize]byte

ShaHash is used in several of the bitmessage messages and common structures. It typically represents the double sha256 of data.

func NewShaHash

func NewShaHash(newHash []byte) (*ShaHash, error)

NewShaHash returns a new ShaHash from a byte slice. An error is returned if the number of bytes passed in is not HashSize.

func NewShaHashFromStr

func NewShaHashFromStr(hash string) (*ShaHash, error)

NewShaHashFromStr creates a ShaHash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the ShaHash.

func (*ShaHash) Bytes

func (hash *ShaHash) Bytes() []byte

Bytes returns the bytes which represent the hash as a byte slice.

func (*ShaHash) IsEqual

func (hash *ShaHash) IsEqual(target *ShaHash) bool

IsEqual returns true if target is the same as hash.

func (*ShaHash) SetBytes

func (hash *ShaHash) SetBytes(newHash []byte) error

SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not HashSize.

func (ShaHash) String

func (hash ShaHash) String() string

String returns the ShaHash as the hexadecimal string of the byte-reversed hash.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL