Documentation ¶
Overview ¶
Package dfmt implements message and subdomain formatting utilities as per DDRP [PIP-7](https://ddrp.network/docs/spec/pip-6.html).
Reading Envelopes ¶
To read envelopes from an io.Reader, use the DecodeEnvelope method:
r := NewBlobReader("some-tld") for { envelope, err := DecodeEnvelope(r) if envelope == nil { break } if err != nil { log.Fatalf("error: %v", err) } fmt.Println(string(envelope.Message.Type())) }
Similarly, to stream envelope to an io.Writer, use the EncodeEnvelope method:
envelope := NewEnvelope(0, NewLike([32]byte{})) w := NewBlobWriter("some-tld") if err := EncodeEnvelope(w, envelope); err != nil { log.Fatalf("error: %v", err) }
Index ¶
- Constants
- Variables
- func EncodeEnvelope(w io.Writer, envelope *Envelope) error
- func HashEnvelope(envelope *Envelope, subdomain string, tld string) ([32]byte, error)
- func IsSubdomainBlob(r io.Reader) (bool, error)
- func NewGUID() [8]byte
- func NewSubdomainDataReader(r io.ReaderAt) *io.SectionReader
- func NewSubdomainRecordsReader(r io.ReaderAt) *io.SectionReader
- type Connection
- type Envelope
- type Media
- type Message
- type Moderation
- type Post
- type SubdomainRecord
- type UnknownMessage
Constants ¶
const ( // UnknownSubtype is used to represent a subtype value that // is unknown to its parent. UnknownSubtype = "UNKNOWN" // BlobLen is the maximum size of a DDRP blob. BlobLen = 16 * 1024 * 1024 ConnectionTypeFollow = "FOLLOW" ConnectionTypeBlock = "BLOCK" ModerationTypeLike = "LIKE" ModerationTypePin = "PIN" )
const ( // The maximum length a given subdomain can be. See specification. MaxSubdomainLen = 15 // The end offset at which subdomain records can be found. EndSubdomainRecordsOffset = 32 * 1024 // Magic bytes denoting a blob that contains subdomains. SubdomainMagic = "SUB" // The end offset for reserved blob data. EndReservedDataOffset = 64 * 1024 )
Variables ¶
var ( // DefaultSubtype is used to signify an empty subtype. DefaultSubtype = [4]byte{0x00, 0x00, 0x00, 0x00} // DefaultVersion is used to signify the default message version. DefaultVersion = uint8(1) // PostType contains the PST MessageType. PostType = [3]byte{0x50, 0x53, 0x54} // ConnectionType contains the CNT MessageType. ConnectionType = [3]byte{0x43, 0x4E, 0x54} // FollowSubtype contains the F\00\00\00 Connection subtype. FollowSubtype = [4]byte{0x46, 0x00, 0x00, 0x00} // BlockSubtype contains the B\00\00\00 Connection subtype. BlockSubtype = [4]byte{0x42, 0x00, 0x00, 0x00} // MediaType contains the MDA MessageType. MediaType = [3]byte{0x4D, 0x44, 0x41} // ModerationType contains the MOD MessageType. ModerationType = [3]byte{0x4D, 0x4F, 0x44} // LikeSubtype contains the L\00\00\00 Moderation subtype. LikeSubtype = [4]byte{0x4C, 0x00, 0x00, 0x00} // PinSubtype contains the P\00\00\00 Moderation subtype. PinSubtype = [4]byte{0x50, 0x00, 0x00, 0x00} )
Functions ¶
func EncodeEnvelope ¶
EncodeEnvelope writes an Envelope to a Writer. It writes the Envelope to an in-memory buffer first so that the Envelope's length field can be written to the underlying Writer before the Envelope's content.
func HashEnvelope ¶
func IsSubdomainBlob ¶ added in v1.7.0
IsSubdomainBlob reads the first three bytes of the provided reader, and returns true if they equal the subdomain blob magic bytes.
func NewSubdomainDataReader ¶ added in v1.9.0
func NewSubdomainDataReader(r io.ReaderAt) *io.SectionReader
NewSubdomainDataReader returns an io.SectionReader that is limited to the portion of the underlying io.readerAt that can contain subdomain data.
func NewSubdomainRecordsReader ¶
func NewSubdomainRecordsReader(r io.ReaderAt) *io.SectionReader
NewSubdomainRecordsReader returns an io.SectionReader that is limited to the portion of the underlying io.ReaderAt that can contain subdomain records.
Types ¶
type Connection ¶
Connection is a container for DDRP Connection messages.
func NewConnection ¶
func NewConnection(version uint8, subtype [4]byte) *Connection
NewConnection returns a Connection with the given subtype.
func NewFollow ¶
func NewFollow() *Connection
NewFollow returns a Connection with the Follow subtype.
func (*Connection) ConnectionType ¶
func (c *Connection) ConnectionType() string
ConnectionType returns the human-readable representation of the Connection's subtype. Can be ConnectionTypeFollow, ConnectionTypeBlock, or UnknownSubtype.
func (*Connection) Subtype ¶
func (c *Connection) Subtype() [4]byte
func (*Connection) Type ¶
func (c *Connection) Type() [3]byte
func (*Connection) Version ¶ added in v1.3.0
func (c *Connection) Version() uint8
type Envelope ¶
type Envelope struct { ID [8]byte NameIndex uint8 Timestamp time.Time Signature []byte Message Message AdditionalData []byte }
An Envelope is a container for a Message. See doc.go for examples of how Envelopes and Messages are structured on the wire.
func DecodeEnvelope ¶
DecodeEnvelope reads an Envelope from a Reader. It reads the Envelope to an in-memory buffer first after reading the Envelope's length field. DecodeEnvelope will return (nil, nil) if \x00 is encountered for the envelope's length, and is a signal to stop reading.
func NewEnvelope ¶
NewEnvelope constructs a new Envelope.
func (*Envelope) Decode ¶
Decode reads an Envelope from the Reader. This method should generally not be used directly because it does not read the Envelope's length field. DecodeEnvelope should be used instead. The Reader passed to this method must be bounded: ioutil.ReadAll is used to populate the AdditionalData field, which will cause unbounded Readers to hang. If an unsupported MessageType is encountered, the type of the Message field will be UnknownMessage and the AdditionalData field will be empty.
type Media ¶
type Media struct { Filename string MimeType string Content []byte // contains filtered or unexported fields }
Media is a container for DDRP Media messages.
type Message ¶
type Message interface { dwire.EncodeDecoder // Type returns the message's 3-byte supertype. Type() [3]byte // Version returns the message's version. Version() uint8 // Subtype returns the message's 5-byte subtype. Subtype() [4]byte }
Message is the generic interface to the various DDRP social message types. See doc.go for more about how Envelopes and Messages are structures on the wire.
type Moderation ¶
type Moderation struct { Reference [32]byte // contains filtered or unexported fields }
Moderation is a container for DDRP Moderation messages.
func NewModeration ¶
func NewModeration(version uint8, subtype [4]byte) *Moderation
NewModeration returns a Moderation with the given subtype.
func (*Moderation) ModerationType ¶
func (m *Moderation) ModerationType() string
ModerationType returns the human-readable representation of the Moderation's subtype. Can be ModerationTypeLike, ModerationTypePin, or UnknownSubtype.
func (*Moderation) Subtype ¶
func (m *Moderation) Subtype() [4]byte
func (*Moderation) Type ¶
func (m *Moderation) Type() [3]byte
func (*Moderation) Version ¶ added in v1.3.0
func (m *Moderation) Version() uint8
type Post ¶
type Post struct { Body string Title string Reference [32]byte Topic string Tags []string // contains filtered or unexported fields }
Post is a container for DDRP Post messages.
type SubdomainRecord ¶
type SubdomainRecord struct { // The subdomain itself. Name string // The index identifying this subdomain. Index uint8 // Public key belonging to this subdomain. Currently unused. PublicKey [33]byte }
A SubdomainRecord holds information about DDRP blob subdomain data.
type UnknownMessage ¶
type UnknownMessage struct { // MessageType is the type received on-the-wire. MessageType [3]byte // MessageVersion is the version received on-the-wire. MessageVersion uint8 // MessageSubtype is the subtype received on-the-wire. MessageSubtype [4]byte // Data is a byte array of the message's contents. Data []byte }
UnknownMessage represents a correctly-formatted but unknown DDRP message.
func (*UnknownMessage) Subtype ¶
func (u *UnknownMessage) Subtype() [4]byte
func (*UnknownMessage) Type ¶
func (u *UnknownMessage) Type() [3]byte
func (*UnknownMessage) Version ¶ added in v1.3.0
func (u *UnknownMessage) Version() uint8