diff options
Diffstat (limited to 'src/gnunet/message/msg_gns.go')
-rw-r--r-- | src/gnunet/message/msg_gns.go | 65 |
1 files changed, 28 insertions, 37 deletions
diff --git a/src/gnunet/message/msg_gns.go b/src/gnunet/message/msg_gns.go index 0f285ee..0b96e88 100644 --- a/src/gnunet/message/msg_gns.go +++ b/src/gnunet/message/msg_gns.go | |||
@@ -34,27 +34,25 @@ import ( | |||
34 | 34 | ||
35 | // LookupMsg is a request message for a GNS name lookup | 35 | // LookupMsg is a request message for a GNS name lookup |
36 | type LookupMsg struct { | 36 | type LookupMsg struct { |
37 | MsgSize uint16 `order:"big"` // total size of message | 37 | MsgHeader |
38 | MsgType uint16 `order:"big"` // GNS_LOOKUP (500) | ||
39 | ID uint32 `order:"big"` // Unique identifier for this request (for key collisions). | 38 | ID uint32 `order:"big"` // Unique identifier for this request (for key collisions). |
40 | Zone *crypto.ZoneKey `` // Zone that is to be used for lookup | 39 | Zone *crypto.ZoneKey `` // Zone that is to be used for lookup |
41 | Options uint16 `order:"big"` // Local options for where to look for results | 40 | Options uint16 `order:"big"` // Local options for where to look for results |
42 | Reserved uint16 `order:"big"` // Always 0 | 41 | Reserved uint16 `order:"big"` // Always 0 |
43 | Type uint32 `order:"big"` // the type of record to look up | 42 | RType uint32 `order:"big"` // the type of record to look up |
44 | Name []byte `size:"*"` // zero-terminated name to look up | 43 | Name []byte `size:"*"` // zero-terminated name to look up |
45 | } | 44 | } |
46 | 45 | ||
47 | // NewGNSLookupMsg creates a new default message. | 46 | // NewGNSLookupMsg creates a new default message. |
48 | func NewGNSLookupMsg() *LookupMsg { | 47 | func NewGNSLookupMsg() *LookupMsg { |
49 | return &LookupMsg{ | 48 | return &LookupMsg{ |
50 | MsgSize: 48, // record size with no name | 49 | MsgHeader: MsgHeader{48, enums.MSG_GNS_LOOKUP}, |
51 | MsgType: GNS_LOOKUP, | 50 | ID: 0, |
52 | ID: 0, | 51 | Zone: nil, |
53 | Zone: nil, | 52 | Options: uint16(enums.GNS_LO_DEFAULT), |
54 | Options: uint16(enums.GNS_LO_DEFAULT), | 53 | Reserved: 0, |
55 | Reserved: 0, | 54 | RType: uint32(enums.GNS_TYPE_ANY), |
56 | Type: uint32(enums.GNS_TYPE_ANY), | 55 | Name: nil, |
57 | Name: nil, | ||
58 | } | 56 | } |
59 | } | 57 | } |
60 | 58 | ||
@@ -79,12 +77,7 @@ func (m *LookupMsg) GetName() string { | |||
79 | func (m *LookupMsg) String() string { | 77 | func (m *LookupMsg) String() string { |
80 | return fmt.Sprintf( | 78 | return fmt.Sprintf( |
81 | "GNSLookupMsg{Id=%d,Zone=%s,Options=%d,Type=%d,Name=%s}", | 79 | "GNSLookupMsg{Id=%d,Zone=%s,Options=%d,Type=%d,Name=%s}", |
82 | m.ID, m.Zone.ID(), m.Options, m.Type, m.GetName()) | 80 | m.ID, m.Zone.ID(), m.Options, m.RType, m.GetName()) |
83 | } | ||
84 | |||
85 | // Header returns the message header in a separate instance. | ||
86 | func (m *LookupMsg) Header() *Header { | ||
87 | return &Header{m.MsgSize, m.MsgType} | ||
88 | } | 81 | } |
89 | 82 | ||
90 | //---------------------------------------------------------------------- | 83 | //---------------------------------------------------------------------- |
@@ -128,14 +121,14 @@ func (rs *RecordSet) SetPadding() { | |||
128 | rs.Padding = make([]byte, n-size) | 121 | rs.Padding = make([]byte, n-size) |
129 | } | 122 | } |
130 | 123 | ||
131 | // Expires returns the earliest expiration timestamp for the records. | 124 | // Expire returns the earliest expiration timestamp for the records. |
132 | func (rs *RecordSet) Expires() util.AbsoluteTime { | 125 | func (rs *RecordSet) Expire() util.AbsoluteTime { |
133 | var expires util.AbsoluteTime | 126 | var expires util.AbsoluteTime |
134 | for i, rr := range rs.Records { | 127 | for i, rr := range rs.Records { |
135 | if i == 0 { | 128 | if i == 0 { |
136 | expires = rr.Expires | 129 | expires = rr.Expire |
137 | } else if rr.Expires.Compare(expires) < 0 { | 130 | } else if rr.Expire.Compare(expires) < 0 { |
138 | expires = rr.Expires | 131 | expires = rr.Expire |
139 | } | 132 | } |
140 | } | 133 | } |
141 | return expires | 134 | return expires |
@@ -144,23 +137,22 @@ func (rs *RecordSet) Expires() util.AbsoluteTime { | |||
144 | // ResourceRecord is the GNUnet-specific representation of resource | 137 | // ResourceRecord is the GNUnet-specific representation of resource |
145 | // records (not to be confused with DNS resource records). | 138 | // records (not to be confused with DNS resource records). |
146 | type ResourceRecord struct { | 139 | type ResourceRecord struct { |
147 | Expires util.AbsoluteTime // Expiration time for the record | 140 | Expire util.AbsoluteTime // Expiration time for the record |
148 | Size uint32 `order:"big"` // Number of bytes in 'Data' | 141 | Size uint32 `order:"big"` // Number of bytes in 'Data' |
149 | Type uint32 `order:"big"` // Type of the GNS/DNS record | 142 | RType uint32 `order:"big"` // Type of the GNS/DNS record |
150 | Flags uint32 `order:"big"` // Flags for the record | 143 | Flags uint32 `order:"big"` // Flags for the record |
151 | Data []byte `size:"Size"` // Record data | 144 | Data []byte `size:"Size"` // Record data |
152 | } | 145 | } |
153 | 146 | ||
154 | // String returns a human-readable representation of the message. | 147 | // String returns a human-readable representation of the message. |
155 | func (r *ResourceRecord) String() string { | 148 | func (r *ResourceRecord) String() string { |
156 | return fmt.Sprintf("GNSResourceRecord{type=%s,expire=%s,flags=%d,size=%d}", | 149 | return fmt.Sprintf("GNSResourceRecord{type=%s,expire=%s,flags=%d,size=%d}", |
157 | enums.GNSType(r.Type).String(), r.Expires, r.Flags, r.Size) | 150 | enums.GNSType(r.RType).String(), r.Expire, r.Flags, r.Size) |
158 | } | 151 | } |
159 | 152 | ||
160 | // LookupResultMsg is a response message for a GNS name lookup request | 153 | // LookupResultMsg is a response message for a GNS name lookup request |
161 | type LookupResultMsg struct { | 154 | type LookupResultMsg struct { |
162 | MsgSize uint16 `order:"big"` // total size of message | 155 | MsgHeader |
163 | MsgType uint16 `order:"big"` // GNS_LOOKUP_RESULT (501) | ||
164 | ID uint32 `order:"big"` // Unique identifier for this request (for key collisions). | 156 | ID uint32 `order:"big"` // Unique identifier for this request (for key collisions). |
165 | Count uint32 `order:"big"` // The number of records contained in response | 157 | Count uint32 `order:"big"` // The number of records contained in response |
166 | Records []*ResourceRecord `size:"Count"` // GNS resource records | 158 | Records []*ResourceRecord `size:"Count"` // GNS resource records |
@@ -169,11 +161,10 @@ type LookupResultMsg struct { | |||
169 | // NewGNSLookupResultMsg returns a new lookup result message | 161 | // NewGNSLookupResultMsg returns a new lookup result message |
170 | func NewGNSLookupResultMsg(id uint32) *LookupResultMsg { | 162 | func NewGNSLookupResultMsg(id uint32) *LookupResultMsg { |
171 | return &LookupResultMsg{ | 163 | return &LookupResultMsg{ |
172 | MsgSize: 12, // Empty result (no records) | 164 | MsgHeader: MsgHeader{12, enums.MSG_GNS_LOOKUP_RESULT}, |
173 | MsgType: GNS_LOOKUP_RESULT, | 165 | ID: id, |
174 | ID: id, | 166 | Count: 0, |
175 | Count: 0, | 167 | Records: make([]*ResourceRecord, 0), |
176 | Records: make([]*ResourceRecord, 0), | ||
177 | } | 168 | } |
178 | } | 169 | } |
179 | 170 | ||
@@ -195,6 +186,6 @@ func (m *LookupResultMsg) String() string { | |||
195 | } | 186 | } |
196 | 187 | ||
197 | // Header returns the message header in a separate instance. | 188 | // Header returns the message header in a separate instance. |
198 | func (m *LookupResultMsg) Header() *Header { | 189 | func (m *LookupResultMsg) Header() *MsgHeader { |
199 | return &Header{m.MsgSize, m.MsgType} | 190 | return &MsgHeader{m.MsgSize, m.MsgType} |
200 | } | 191 | } |