aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet/message/msg_namecache.go
blob: 9e3312d0f25cafaf5171823f0bccb727277cc792 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package message

import (
	"encoding/hex"
	"fmt"

	"gnunet/crypto"
	"gnunet/util"
)

//----------------------------------------------------------------------
// NAMECACHE_LOOKUP_BLOCK
//----------------------------------------------------------------------

// NamecacheLookupMsg
type NamecacheLookupMsg struct {
	MsgSize uint16           `order:"big"` // total size of message
	MsgType uint16           `order:"big"` // NAMECACHE_LOOKUP_BLOCK (431)
	Id      uint32           `order:"big"` // Request Id
	Query   *crypto.HashCode // Query data
}

// NewNamecacheLookupMsg creates a new default message.
func NewNamecacheLookupMsg(query *crypto.HashCode) *NamecacheLookupMsg {
	if query == nil {
		query = crypto.NewHashCode()
	}
	return &NamecacheLookupMsg{
		MsgSize: 72,
		MsgType: NAMECACHE_LOOKUP_BLOCK,
		Id:      0,
		Query:   query,
	}
}

// String returns a human-readable representation of the message.
func (m *NamecacheLookupMsg) String() string {
	return fmt.Sprintf("NamecacheLookupMsg{Id=%d,Query=%s}",
		m.Id, hex.EncodeToString(m.Query.Bits))
}

// Header returns the message header in a separate instance.
func (msg *NamecacheLookupMsg) Header() *MessageHeader {
	return &MessageHeader{msg.MsgSize, msg.MsgType}
}

//----------------------------------------------------------------------
// NAMECACHE_LOOKUP_BLOCK_RESPONSE
//----------------------------------------------------------------------

// NamecacheLookupResultMsg
type NamecacheLookupResultMsg struct {
	MsgSize    uint16            `order:"big"` // total size of message
	MsgType    uint16            `order:"big"` // NAMECACHE_LOOKUP_BLOCK_RESPONSE (432)
	Id         uint32            `order:"big"` // Request Id
	Expire     util.AbsoluteTime // Expiration time
	Signature  []byte            `size:"64"` // ECDSA signature
	DerivedKey []byte            `size:"32"` // Derived public key
	EncData    []byte            `size:"*"`  // Encrypted block data
}

// NewNamecacheLookupResultMsg creates a new default message.
func NewNamecacheLookupResultMsg() *NamecacheLookupResultMsg {
	return &NamecacheLookupResultMsg{
		MsgSize:    112,
		MsgType:    NAMECACHE_LOOKUP_BLOCK_RESPONSE,
		Id:         0,
		Expire:     *new(util.AbsoluteTime),
		Signature:  make([]byte, 64),
		DerivedKey: make([]byte, 32),
		EncData:    make([]byte, 0),
	}
}

// String returns a human-readable representation of the message.
func (m *NamecacheLookupResultMsg) String() string {
	return fmt.Sprintf("NamecacheLookupResultMsg{id=%d,expire=%s}",
		m.Id, m.Expire)
}

// Header returns the message header in a separate instance.
func (msg *NamecacheLookupResultMsg) Header() *MessageHeader {
	return &MessageHeader{msg.MsgSize, msg.MsgType}
}