diff options
author | Bernd Fix <brf@hoi-polloi.org> | 2022-08-21 16:40:12 +0200 |
---|---|---|
committer | Bernd Fix <brf@hoi-polloi.org> | 2022-08-21 16:40:12 +0200 |
commit | 21d7292dbd062ff11194fdc235a3d54830d7ba57 (patch) | |
tree | 75b5b1c620f4ac9cb722330c6bd9cbcdb24c7700 | |
parent | 5b03f7567ad8242cc87924c3920dfc04420365ef (diff) | |
download | gnunet-go-21d7292dbd062ff11194fdc235a3d54830d7ba57.tar.gz gnunet-go-21d7292dbd062ff11194fdc235a3d54830d7ba57.zip |
Integration test: bug fixes 1st round.
37 files changed, 314 insertions, 257 deletions
@@ -225,9 +225,25 @@ ${GOPATH}/bin/gnunet-service-dht-go -c dhtu-config.json 2>&1 | tee run.log | |||
225 | 225 | ||
226 | ## Testing `GNS` | 226 | ## Testing `GNS` |
227 | 227 | ||
228 | You need to have (all) GNUnet services up and running. | 228 | **N.B.**: The GNS service is currently not up-to-date. To test it, you need to |
229 | check out version v0.1.23 (the latest tested version) and a matching GNUnet | ||
230 | version as well (latest as of May 2020) to be on a safe side. You also need to | ||
231 | have (all) GNUnet services up and running. | ||
229 | 232 | ||
230 | ### Setting up the configuration file | 233 | ### Setting up a modified configuration for GNUnet |
234 | |||
235 | You need to tell the GNUnet client which GNS service to use (either the default | ||
236 | or the `gnunet-go` version) by modifying the GNS service socket. Copy your | ||
237 | configuration file to `gns-go.comf` and modify the `[gns]` sectiom: | ||
238 | |||
239 | ``` | ||
240 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-gns-go.sock | ||
241 | ``` | ||
242 | |||
243 | This will ensure that clients (and other services) talk to the `gnunet-go` | ||
244 | GNS service. | ||
245 | |||
246 | ### Setting up the configuration file (gnunet-go) | ||
231 | 247 | ||
232 | Copy the example `gnunet-config.json` to `gns-config.json` and modify the | 248 | Copy the example `gnunet-config.json` to `gns-config.json` and modify the |
233 | `network` and `local` sections: | 249 | `network` and `local` sections: |
diff --git a/src/gnunet/cmd/revoke-zonekey/main.go b/src/gnunet/cmd/revoke-zonekey/main.go index fe56946..5769eff 100644 --- a/src/gnunet/cmd/revoke-zonekey/main.go +++ b/src/gnunet/cmd/revoke-zonekey/main.go | |||
@@ -136,16 +136,17 @@ func (r *RevData) size() int { | |||
136 | // process run stand-alone from other GNUnet services: | 136 | // process run stand-alone from other GNUnet services: |
137 | // | 137 | // |
138 | // (1) Generate the desired PoWs for the public zone key: | 138 | // (1) Generate the desired PoWs for the public zone key: |
139 | // This process can be started, stopped and resumed, so the long | ||
140 | // calculation time (usually days or even weeks) can be interrupted if | ||
141 | // desired. For security reasons you should only pass the "-z" argument to | ||
142 | // this step but not the "-k" argument (private key) as it is not required | ||
143 | // to calculate the PoWs. | ||
144 | // | 139 | // |
140 | // This process can be started, stopped and resumed, so the long | ||
141 | // calculation time (usually days or even weeks) can be interrupted if | ||
142 | // desired. For security reasons you should only pass the "-z" argument to | ||
143 | // this step but not the "-k" argument (private key) as it is not required | ||
144 | // to calculate the PoWs. | ||
145 | // | 145 | // |
146 | // (2) A fully generated PoW set can be signed with the private key to create | 146 | // (2) A fully generated PoW set can be signed with the private key to create |
147 | // the final revocation data to be send out. This requires to pass the "-k" | 147 | // |
148 | // and "-z" argument. | 148 | // the final revocation data to be send out. This requires to pass the "-k" |
149 | // and "-z" argument. | ||
149 | // | 150 | // |
150 | // The two steps can be run (sequentially) on separate machines; step one requires | 151 | // The two steps can be run (sequentially) on separate machines; step one requires |
151 | // computing power nd memory and step two requires a trusted environment. | 152 | // computing power nd memory and step two requires a trusted environment. |
diff --git a/src/gnunet/config/config.go b/src/gnunet/config/config.go index 504ed82..526b7b8 100644 --- a/src/gnunet/config/config.go +++ b/src/gnunet/config/config.go | |||
@@ -22,7 +22,7 @@ import ( | |||
22 | "encoding/json" | 22 | "encoding/json" |
23 | "fmt" | 23 | "fmt" |
24 | "gnunet/util" | 24 | "gnunet/util" |
25 | "io/ioutil" | 25 | "os" |
26 | "reflect" | 26 | "reflect" |
27 | "regexp" | 27 | "regexp" |
28 | "strings" | 28 | "strings" |
@@ -172,7 +172,7 @@ var ( | |||
172 | // the Config data structure. | 172 | // the Config data structure. |
173 | func ParseConfig(fileName string) (err error) { | 173 | func ParseConfig(fileName string) (err error) { |
174 | // parse configuration file | 174 | // parse configuration file |
175 | file, err := ioutil.ReadFile(fileName) | 175 | file, err := os.ReadFile(fileName) |
176 | if err != nil { | 176 | if err != nil { |
177 | return | 177 | return |
178 | } | 178 | } |
diff --git a/src/gnunet/config/config_test.go b/src/gnunet/config/config_test.go index b61cb67..3a77892 100644 --- a/src/gnunet/config/config_test.go +++ b/src/gnunet/config/config_test.go | |||
@@ -20,7 +20,7 @@ package config | |||
20 | 20 | ||
21 | import ( | 21 | import ( |
22 | "encoding/json" | 22 | "encoding/json" |
23 | "io/ioutil" | 23 | "os" |
24 | "testing" | 24 | "testing" |
25 | 25 | ||
26 | "github.com/bfix/gospel/logger" | 26 | "github.com/bfix/gospel/logger" |
@@ -30,7 +30,7 @@ func TestConfigRead(t *testing.T) { | |||
30 | logger.SetLogLevel(logger.WARN) | 30 | logger.SetLogLevel(logger.WARN) |
31 | 31 | ||
32 | // read configuration file | 32 | // read configuration file |
33 | data, err := ioutil.ReadFile("./gnunet-config.json") | 33 | data, err := os.ReadFile("./gnunet-config.json") |
34 | if err != nil { | 34 | if err != nil { |
35 | t.Fatal(err) | 35 | t.Fatal(err) |
36 | } | 36 | } |
diff --git a/src/gnunet/core/core.go b/src/gnunet/core/core.go index 46a53a4..a0c5f02 100644 --- a/src/gnunet/core/core.go +++ b/src/gnunet/core/core.go | |||
@@ -33,7 +33,7 @@ import ( | |||
33 | "github.com/bfix/gospel/logger" | 33 | "github.com/bfix/gospel/logger" |
34 | ) | 34 | ) |
35 | 35 | ||
36 | //---------------------------------------------------------------------- | 36 | // ---------------------------------------------------------------------- |
37 | // Core-related error codes | 37 | // Core-related error codes |
38 | var ( | 38 | var ( |
39 | ErrCoreNoUpnpDyn = errors.New("no dynamic port with UPnP") | 39 | ErrCoreNoUpnpDyn = errors.New("no dynamic port with UPnP") |
@@ -44,7 +44,7 @@ var ( | |||
44 | // CtxKey is a value-context key | 44 | // CtxKey is a value-context key |
45 | type CtxKey string | 45 | type CtxKey string |
46 | 46 | ||
47 | //---------------------------------------------------------------------- | 47 | // ---------------------------------------------------------------------- |
48 | // EndpointRef is a reference to an endpoint instance managed by core. | 48 | // EndpointRef is a reference to an endpoint instance managed by core. |
49 | type EndpointRef struct { | 49 | type EndpointRef struct { |
50 | id string // endpoint identifier in configuration | 50 | id string // endpoint identifier in configuration |
@@ -53,7 +53,7 @@ type EndpointRef struct { | |||
53 | upnpID string // UPNP identifier (empty if unused) | 53 | upnpID string // UPNP identifier (empty if unused) |
54 | } | 54 | } |
55 | 55 | ||
56 | //---------------------------------------------------------------------- | 56 | // ---------------------------------------------------------------------- |
57 | // Core service | 57 | // Core service |
58 | type Core struct { | 58 | type Core struct { |
59 | // local peer instance | 59 | // local peer instance |
diff --git a/src/gnunet/core/event.go b/src/gnunet/core/event.go index d24352d..121d76b 100644 --- a/src/gnunet/core/event.go +++ b/src/gnunet/core/event.go | |||
@@ -31,6 +31,7 @@ import ( | |||
31 | //---------------------------------------------------------------------- | 31 | //---------------------------------------------------------------------- |
32 | 32 | ||
33 | // Event types | 33 | // Event types |
34 | // | ||
34 | //nolint:stylecheck // allow non-camel-case in constants | 35 | //nolint:stylecheck // allow non-camel-case in constants |
35 | const ( | 36 | const ( |
36 | EV_CONNECT = iota // peer connected | 37 | EV_CONNECT = iota // peer connected |
diff --git a/src/gnunet/core/peer.go b/src/gnunet/core/peer.go index fe171b4..23f370f 100644 --- a/src/gnunet/core/peer.go +++ b/src/gnunet/core/peer.go | |||
@@ -103,7 +103,7 @@ func (p *Peer) HelloData(ttl time.Duration, a []*util.Address) (h *blocks.HelloB | |||
103 | // assemble HELLO data | 103 | // assemble HELLO data |
104 | h = new(blocks.HelloBlock) | 104 | h = new(blocks.HelloBlock) |
105 | h.PeerID = p.GetID() | 105 | h.PeerID = p.GetID() |
106 | h.Expire_ = util.NewAbsoluteTime(time.Now().Add(ttl)) | 106 | h.SetExpire(ttl) |
107 | h.SetAddresses(a) | 107 | h.SetAddresses(a) |
108 | 108 | ||
109 | // sign data | 109 | // sign data |
diff --git a/src/gnunet/crypto/signature.go b/src/gnunet/crypto/signature.go index 1e0acbb..1325f18 100644 --- a/src/gnunet/crypto/signature.go +++ b/src/gnunet/crypto/signature.go | |||
@@ -18,12 +18,15 @@ | |||
18 | 18 | ||
19 | package crypto | 19 | package crypto |
20 | 20 | ||
21 | import "gnunet/util" | 21 | import ( |
22 | "gnunet/enums" | ||
23 | "gnunet/util" | ||
24 | ) | ||
22 | 25 | ||
23 | // SignaturePurpose is the GNUnet data structure used as header for signed data. | 26 | // SignaturePurpose is the GNUnet data structure used as header for signed data. |
24 | type SignaturePurpose struct { | 27 | type SignaturePurpose struct { |
25 | Size uint32 `order:"big"` // How many bytes are signed? | 28 | Size uint32 `order:"big"` // How many bytes are signed? |
26 | Purpose uint32 `order:"big"` // Signature purpose | 29 | Purpose enums.SigPurpose `order:"big"` // Signature purpose |
27 | } | 30 | } |
28 | 31 | ||
29 | // Signable interface for objects that can get signed by peer | 32 | // Signable interface for objects that can get signed by peer |
diff --git a/src/gnunet/enums/gnunet-signature.tpl b/src/gnunet/enums/gnunet-signature.tpl index 5af6c28..2bf63b3 100644 --- a/src/gnunet/enums/gnunet-signature.tpl +++ b/src/gnunet/enums/gnunet-signature.tpl | |||
@@ -3,7 +3,7 @@ | |||
3 | //nolint:stylecheck // allow non-camel-case for constants | 3 | //nolint:stylecheck // allow non-camel-case for constants |
4 | package enums | 4 | package enums |
5 | 5 | ||
6 | type SigPurpose int | 6 | type SigPurpose uint32 |
7 | 7 | ||
8 | // Signature purpose values | 8 | // Signature purpose values |
9 | const ( | 9 | const ( |
diff --git a/src/gnunet/enums/messages.go b/src/gnunet/enums/messages.go index af9baeb..ca76d3a 100644 --- a/src/gnunet/enums/messages.go +++ b/src/gnunet/enums/messages.go | |||
@@ -20,6 +20,7 @@ | |||
20 | package enums | 20 | package enums |
21 | 21 | ||
22 | // MsgType for GNUnet message type identifiers | 22 | // MsgType for GNUnet message type identifiers |
23 | // | ||
23 | //go:generate stringer -type=MsgType | 24 | //go:generate stringer -type=MsgType |
24 | type MsgType uint16 | 25 | type MsgType uint16 |
25 | 26 | ||
diff --git a/src/gnunet/enums/signature_purpose.go b/src/gnunet/enums/signature_purpose.go index 0c1901e..31f6eca 100644 --- a/src/gnunet/enums/signature_purpose.go +++ b/src/gnunet/enums/signature_purpose.go | |||
@@ -3,7 +3,7 @@ | |||
3 | //nolint:stylecheck // allow non-camel-case for constants | 3 | //nolint:stylecheck // allow non-camel-case for constants |
4 | package enums | 4 | package enums |
5 | 5 | ||
6 | type SigPurpose int | 6 | type SigPurpose uint32 |
7 | 7 | ||
8 | // Signature purpose values | 8 | // Signature purpose values |
9 | const ( | 9 | const ( |
diff --git a/src/gnunet/enums/sigpurpose_string.go b/src/gnunet/enums/sigpurpose_string.go index cdbdfc8..dd392ab 100644 --- a/src/gnunet/enums/sigpurpose_string.go +++ b/src/gnunet/enums/sigpurpose_string.go | |||
@@ -58,7 +58,7 @@ var ( | |||
58 | 58 | ||
59 | func (i SigPurpose) String() string { | 59 | func (i SigPurpose) String() string { |
60 | switch { | 60 | switch { |
61 | case 0 <= i && i <= 7: | 61 | case i <= 7: |
62 | return _SigPurpose_name_0[_SigPurpose_index_0[i]:_SigPurpose_index_0[i+1]] | 62 | return _SigPurpose_name_0[_SigPurpose_index_0[i]:_SigPurpose_index_0[i+1]] |
63 | case 11 <= i && i <= 18: | 63 | case 11 <= i && i <= 18: |
64 | i -= 11 | 64 | i -= 11 |
diff --git a/src/gnunet/message/msg_core.go b/src/gnunet/message/msg_core.go index ae1b9cf..6ebb30e 100644 --- a/src/gnunet/message/msg_core.go +++ b/src/gnunet/message/msg_core.go | |||
@@ -58,7 +58,7 @@ func NewEphemeralKeyMsg() *EphemeralKeyMsg { | |||
58 | SignedBlock: &EphKeyBlock{ | 58 | SignedBlock: &EphKeyBlock{ |
59 | Purpose: &crypto.SignaturePurpose{ | 59 | Purpose: &crypto.SignaturePurpose{ |
60 | Size: 88, | 60 | Size: 88, |
61 | Purpose: uint32(enums.SIG_SET_ECC_KEY), | 61 | Purpose: enums.SIG_SET_ECC_KEY, |
62 | }, | 62 | }, |
63 | CreateTime: util.AbsoluteTimeNow(), | 63 | CreateTime: util.AbsoluteTimeNow(), |
64 | ExpireTime: util.NewRelativeTime(12 * time.Hour), | 64 | ExpireTime: util.NewRelativeTime(12 * time.Hour), |
diff --git a/src/gnunet/message/msg_dht_p2p.go b/src/gnunet/message/msg_dht_p2p.go index f6b24e2..9d1d815 100644 --- a/src/gnunet/message/msg_dht_p2p.go +++ b/src/gnunet/message/msg_dht_p2p.go | |||
@@ -178,20 +178,20 @@ func (m *DHTP2PPutMsg) Update(p *path.Path, pf *blocks.PeerFilter, hop uint16) * | |||
178 | func (m *DHTP2PPutMsg) Path(sender *util.PeerID) *path.Path { | 178 | func (m *DHTP2PPutMsg) Path(sender *util.PeerID) *path.Path { |
179 | // create a "real" path list from message data | 179 | // create a "real" path list from message data |
180 | pth := path.NewPath(crypto.Hash(m.Block), m.Expire) | 180 | pth := path.NewPath(crypto.Hash(m.Block), m.Expire) |
181 | pth.Flags = m.Flags | ||
181 | 182 | ||
182 | // return empty path if recording is switched off | 183 | // return empty path if recording is switched off |
183 | if m.Flags&enums.DHT_RO_RECORD_ROUTE == 0 { | 184 | if pth.Flags&enums.DHT_RO_RECORD_ROUTE == 0 { |
184 | return pth | 185 | return pth |
185 | } | 186 | } |
186 | 187 | ||
187 | // handle truncate origin | 188 | // handle truncate origin |
188 | if m.Flags&enums.DHT_RO_TRUNCATED == 1 { | 189 | if pth.Flags&enums.DHT_RO_TRUNCATED == 1 { |
189 | if m.TruncOrigin == nil { | 190 | if m.TruncOrigin == nil { |
190 | logger.Printf(logger.WARN, "[path] truncated but no origin - flag reset") | 191 | logger.Printf(logger.WARN, "[path] truncated but no origin - flag reset") |
191 | m.Flags &^= enums.DHT_RO_TRUNCATED | 192 | pth.Flags &^= enums.DHT_RO_TRUNCATED |
192 | } else { | 193 | } else { |
193 | pth.TruncOrigin = m.TruncOrigin | 194 | pth.TruncOrigin = m.TruncOrigin |
194 | pth.Flags |= path.PathTruncated | ||
195 | } | 195 | } |
196 | } | 196 | } |
197 | 197 | ||
@@ -204,7 +204,6 @@ func (m *DHTP2PPutMsg) Path(sender *util.PeerID) *path.Path { | |||
204 | logger.Printf(logger.WARN, "[path] - last hop signature missing - path reset") | 204 | logger.Printf(logger.WARN, "[path] - last hop signature missing - path reset") |
205 | return path.NewPath(crypto.Hash(m.Block), m.Expire) | 205 | return path.NewPath(crypto.Hash(m.Block), m.Expire) |
206 | } | 206 | } |
207 | pth.Flags |= path.PathLastHop | ||
208 | pth.LastSig = m.LastSig | 207 | pth.LastSig = m.LastSig |
209 | pth.LastHop = sender | 208 | pth.LastHop = sender |
210 | return pth | 209 | return pth |
@@ -273,8 +272,8 @@ func (m *DHTP2PPutMsg) String() string { | |||
273 | type DHTP2PResultMsg struct { | 272 | type DHTP2PResultMsg struct { |
274 | MsgHeader | 273 | MsgHeader |
275 | BType enums.BlockType `order:"big"` // Block type of result | 274 | BType enums.BlockType `order:"big"` // Block type of result |
276 | Flags uint16 `order:"big"` // Message flags | ||
277 | Reserved uint16 `order:"big"` // Reserved | 275 | Reserved uint16 `order:"big"` // Reserved |
276 | Flags uint16 `order:"big"` // Message flags | ||
278 | PutPathL uint16 `order:"big"` // size of PUTPATH field | 277 | PutPathL uint16 `order:"big"` // size of PUTPATH field |
279 | GetPathL uint16 `order:"big"` // size of GETPATH field | 278 | GetPathL uint16 `order:"big"` // size of GETPATH field |
280 | Expire util.AbsoluteTime `` // expiration date | 279 | Expire util.AbsoluteTime `` // expiration date |
@@ -323,21 +322,22 @@ func (m *DHTP2PResultMsg) NumPath(field string) uint { | |||
323 | func (m *DHTP2PResultMsg) Path(sender *util.PeerID) *path.Path { | 322 | func (m *DHTP2PResultMsg) Path(sender *util.PeerID) *path.Path { |
324 | // create a "real" path list from message data | 323 | // create a "real" path list from message data |
325 | pth := path.NewPath(crypto.Hash(m.Block), m.Expire) | 324 | pth := path.NewPath(crypto.Hash(m.Block), m.Expire) |
325 | pth.Flags = m.Flags | ||
326 | 326 | ||
327 | // return empty path if recording is switched off | 327 | // return empty path if recording is switched off |
328 | if m.Flags&enums.DHT_RO_RECORD_ROUTE == 0 { | 328 | if pth.Flags&enums.DHT_RO_RECORD_ROUTE == 0 { |
329 | return pth | 329 | return pth |
330 | } | 330 | } |
331 | // handle truncate origin | 331 | // handle truncate origin |
332 | if m.Flags&enums.DHT_RO_TRUNCATED == 1 { | 332 | if pth.Flags&enums.DHT_RO_TRUNCATED == 1 { |
333 | if m.TruncOrigin == nil { | 333 | if pth.TruncOrigin == nil { |
334 | logger.Printf(logger.WARN, "[path] truncated but no origin - flag reset") | 334 | logger.Printf(logger.WARN, "[path] truncated but no origin - flag reset") |
335 | m.Flags &^= enums.DHT_RO_TRUNCATED | 335 | pth.Flags &^= enums.DHT_RO_TRUNCATED |
336 | } else { | 336 | } else { |
337 | pth.TruncOrigin = m.TruncOrigin | 337 | pth.TruncOrigin = m.TruncOrigin |
338 | pth.Flags |= path.PathTruncated | ||
339 | } | 338 | } |
340 | } | 339 | } |
340 | |||
341 | // copy path elements | 341 | // copy path elements |
342 | pth.List = util.Clone(m.PathList) | 342 | pth.List = util.Clone(m.PathList) |
343 | pth.NumList = uint16(len(pth.List)) | 343 | pth.NumList = uint16(len(pth.List)) |
@@ -358,7 +358,6 @@ func (m *DHTP2PResultMsg) Path(sender *util.PeerID) *path.Path { | |||
358 | logger.Printf(logger.WARN, "[path] - last hop signature missing - path reset") | 358 | logger.Printf(logger.WARN, "[path] - last hop signature missing - path reset") |
359 | return path.NewPath(crypto.Hash(m.Block), m.Expire) | 359 | return path.NewPath(crypto.Hash(m.Block), m.Expire) |
360 | } | 360 | } |
361 | pth.Flags |= path.PathLastHop | ||
362 | pth.LastSig = m.LastSig | 361 | pth.LastSig = m.LastSig |
363 | pth.LastHop = sender | 362 | pth.LastHop = sender |
364 | return pth | 363 | return pth |
@@ -440,7 +439,7 @@ func (m *DHTP2PResultMsg) Update(pth *path.Path) *DHTP2PResultMsg { | |||
440 | // String returns a human-readable representation of the message. | 439 | // String returns a human-readable representation of the message. |
441 | func (m *DHTP2PResultMsg) String() string { | 440 | func (m *DHTP2PResultMsg) String() string { |
442 | return fmt.Sprintf("DHTP2PResultMsg{btype=%s,putl=%d,getl=%d,flags=%s}", | 441 | return fmt.Sprintf("DHTP2PResultMsg{btype=%s,putl=%d,getl=%d,flags=%s}", |
443 | m.BType, m.PutPathL, m.GetPathL, DHTFlags(uint16(m.Flags))) | 442 | m.BType, m.PutPathL, m.GetPathL, DHTFlags(m.Flags)) |
444 | } | 443 | } |
445 | 444 | ||
446 | //---------------------------------------------------------------------- | 445 | //---------------------------------------------------------------------- |
diff --git a/src/gnunet/message/msg_transport.go b/src/gnunet/message/msg_transport.go index 410e34c..5369ca7 100644 --- a/src/gnunet/message/msg_transport.go +++ b/src/gnunet/message/msg_transport.go | |||
@@ -134,7 +134,7 @@ func NewSignedAddress(a *util.Address) *SignedAddress { | |||
134 | addr := &SignedAddress{ | 134 | addr := &SignedAddress{ |
135 | Purpose: &crypto.SignaturePurpose{ | 135 | Purpose: &crypto.SignaturePurpose{ |
136 | Size: uint32(alen + 20), | 136 | Size: uint32(alen + 20), |
137 | Purpose: uint32(enums.SIG_TRANSPORT_PONG_OWN), | 137 | Purpose: enums.SIG_TRANSPORT_PONG_OWN, |
138 | }, | 138 | }, |
139 | ExpireOn: util.AbsoluteTimeNow().Add(12 * time.Hour), | 139 | ExpireOn: util.AbsoluteTimeNow().Add(12 * time.Hour), |
140 | AddrSize: uint32(alen), | 140 | AddrSize: uint32(alen), |
diff --git a/src/gnunet/service/dht/blocks/filters.go b/src/gnunet/service/dht/blocks/filters.go index b3c7666..a807f1c 100644 --- a/src/gnunet/service/dht/blocks/filters.go +++ b/src/gnunet/service/dht/blocks/filters.go | |||
@@ -73,6 +73,7 @@ func (pf *PeerFilter) Clone() *PeerFilter { | |||
73 | //====================================================================== | 73 | //====================================================================== |
74 | 74 | ||
75 | // ResultFilter return values | 75 | // ResultFilter return values |
76 | // | ||
76 | //nolint:stylecheck // allow non-camel-case in constants | 77 | //nolint:stylecheck // allow non-camel-case in constants |
77 | const ( | 78 | const ( |
78 | RF_MORE = iota // Valid result, and there may be more. | 79 | RF_MORE = iota // Valid result, and there may be more. |
@@ -82,6 +83,7 @@ const ( | |||
82 | ) | 83 | ) |
83 | 84 | ||
84 | // Compare return values | 85 | // Compare return values |
86 | // | ||
85 | //nolint:stylecheck // allow non-camel-case in constants | 87 | //nolint:stylecheck // allow non-camel-case in constants |
86 | const ( | 88 | const ( |
87 | CMP_SAME = iota // the two result filter are the same | 89 | CMP_SAME = iota // the two result filter are the same |
diff --git a/src/gnunet/service/dht/blocks/hello.go b/src/gnunet/service/dht/blocks/hello.go index 2e23cfe..8e2cd77 100644 --- a/src/gnunet/service/dht/blocks/hello.go +++ b/src/gnunet/service/dht/blocks/hello.go | |||
@@ -21,7 +21,6 @@ package blocks | |||
21 | import ( | 21 | import ( |
22 | "bytes" | 22 | "bytes" |
23 | "crypto/sha512" | 23 | "crypto/sha512" |
24 | "encoding/binary" | ||
25 | "errors" | 24 | "errors" |
26 | "fmt" | 25 | "fmt" |
27 | "gnunet/crypto" | 26 | "gnunet/crypto" |
@@ -97,13 +96,13 @@ func (h *HelloBlock) SetAddresses(a []*util.Address) { | |||
97 | // Addresses returns the list of addresses | 96 | // Addresses returns the list of addresses |
98 | func (h *HelloBlock) Addresses() []*util.Address { | 97 | func (h *HelloBlock) Addresses() []*util.Address { |
99 | if h.addrs == nil { | 98 | if h.addrs == nil { |
100 | h.finalize() | 99 | _ = h.finalize() |
101 | } | 100 | } |
102 | return util.Clone(h.addrs) | 101 | return util.Clone(h.addrs) |
103 | } | 102 | } |
104 | 103 | ||
105 | // ParseHelloBlockFromURL parses a HELLO URL of the following form: | 104 | // ParseHelloBlockFromURL parses a HELLO URL of the following form: |
106 | // gnunet://hello/<PeerID>/<signature>/<expire>?<addrs> | 105 | // gnunet://hello/<PeerID>/<signature>/<expire>?<addrs> |
107 | // The addresses are encoded. | 106 | // The addresses are encoded. |
108 | func ParseHelloBlockFromURL(u string, checkExpiry bool) (h *HelloBlock, err error) { | 107 | func ParseHelloBlockFromURL(u string, checkExpiry bool) (h *HelloBlock, err error) { |
109 | // check and trim prefix | 108 | // check and trim prefix |
@@ -302,32 +301,36 @@ func (h *HelloBlock) SetSignature(sig *util.PeerSignature) error { | |||
302 | return nil | 301 | return nil |
303 | } | 302 | } |
304 | 303 | ||
304 | // _SignedData is the structured data to be signed | ||
305 | type _SignedData struct { | ||
306 | Purpose *crypto.SignaturePurpose // signature purpose | ||
307 | Expire util.AbsoluteTime // expiration time | ||
308 | AddrHash *crypto.HashCode // address hash | ||
309 | } | ||
310 | |||
305 | // SignedData assembles a data block for sign and verify operations. | 311 | // SignedData assembles a data block for sign and verify operations. |
306 | func (h *HelloBlock) SignedData() []byte { | 312 | func (h *HelloBlock) SignedData() []byte { |
307 | // hash address block | ||
308 | hAddr := sha512.Sum512(h.AddrBin) | ||
309 | var size uint32 = 80 | ||
310 | purpose := uint32(enums.SIG_HELLO) | ||
311 | |||
312 | // assemble signed data | 313 | // assemble signed data |
313 | buf := new(bytes.Buffer) | 314 | sd := &_SignedData{ |
314 | var n int | 315 | Purpose: &crypto.SignaturePurpose{ |
315 | err := binary.Write(buf, binary.BigEndian, size) | 316 | Size: 80, |
316 | if err == nil { | 317 | Purpose: enums.SIG_HELLO, |
317 | if err = binary.Write(buf, binary.BigEndian, purpose); err == nil { | 318 | }, |
318 | if err = binary.Write(buf, binary.BigEndian, h.Expire_); err == nil { | 319 | Expire: h.Expire_, |
319 | if n, err = buf.Write(hAddr[:]); err == nil { | 320 | AddrHash: crypto.Hash(h.AddrBin), |
320 | if n != len(hAddr[:]) { | 321 | } |
321 | err = errors.New("signed data size mismatch") | 322 | // generate binary representation |
322 | } | 323 | buf, err := data.Marshal(sd) |
323 | } | ||
324 | } | ||
325 | } | ||
326 | } | ||
327 | if err != nil { | 324 | if err != nil { |
328 | logger.Printf(logger.ERROR, "[HelloBlock.SignedData] failed: %s", err.Error()) | 325 | logger.Println(logger.ERROR, "can't serialize HELLO for signature") |
326 | return nil | ||
329 | } | 327 | } |
330 | return buf.Bytes() | 328 | if len(buf) != int(sd.Purpose.Size) { |
329 | logger.Printf(logger.ERROR, "size mismatch for serialized HELLO -- %d -> %d", sd.Purpose.Size, len(buf)) | ||
330 | sd.Purpose.Size = uint32(len(buf)) | ||
331 | return nil | ||
332 | } | ||
333 | return buf | ||
331 | } | 334 | } |
332 | 335 | ||
333 | //---------------------------------------------------------------------- | 336 | //---------------------------------------------------------------------- |
diff --git a/src/gnunet/service/dht/blocks/hello_test.go b/src/gnunet/service/dht/blocks/hello_test.go index d0ef004..8f29344 100644 --- a/src/gnunet/service/dht/blocks/hello_test.go +++ b/src/gnunet/service/dht/blocks/hello_test.go | |||
@@ -20,7 +20,6 @@ package blocks | |||
20 | 20 | ||
21 | import ( | 21 | import ( |
22 | "bytes" | 22 | "bytes" |
23 | "encoding/base64" | ||
24 | "encoding/hex" | 23 | "encoding/hex" |
25 | "gnunet/util" | 24 | "gnunet/util" |
26 | "strings" | 25 | "strings" |
@@ -28,7 +27,6 @@ import ( | |||
28 | "time" | 27 | "time" |
29 | 28 | ||
30 | "github.com/bfix/gospel/crypto/ed25519" | 29 | "github.com/bfix/gospel/crypto/ed25519" |
31 | "github.com/bfix/gospel/data" | ||
32 | ) | 30 | ) |
33 | 31 | ||
34 | var ( | 32 | var ( |
@@ -122,43 +120,3 @@ func TestHelloBytes(t *testing.T) { | |||
122 | t.Fatal("Bytes readback failed") | 120 | t.Fatal("Bytes readback failed") |
123 | } | 121 | } |
124 | } | 122 | } |
125 | |||
126 | func TestHelloDebug(t *testing.T) { | ||
127 | blkData := "QKObXJUbnnghRh9McDDjHaB9IIL6MhhEiQHc8VfO3QMABeZZJJhsA" + | ||
128 | "GlwK3VkcDovLzEyNy4wLjAuMToxMDAwMQBpcCt1ZHA6Ly8xNzIuMT" + | ||
129 | "cuMC40OjEwMDAxAGlwK3VkcDovL1s6OmZmZmY6MTcyLjE3LjAuNF06MTAwMDEA" | ||
130 | buf, err := base64.RawStdEncoding.DecodeString(blkData) | ||
131 | if err != nil { | ||
132 | t.Fatal(err) | ||
133 | } | ||
134 | hb, err := ParseHelloBlockFromBytes(buf) | ||
135 | if err != nil { | ||
136 | t.Fatal(err) | ||
137 | } | ||
138 | ok, err := hb.Verify() | ||
139 | if err != nil { | ||
140 | t.Fatal(err) | ||
141 | } | ||
142 | if !ok { | ||
143 | // trace problem | ||
144 | t.Log("Block: " + hex.EncodeToString(buf)) | ||
145 | t.Log("PeerID: " + hb.PeerID.String()) | ||
146 | t.Log(" -> " + hex.EncodeToString(hb.PeerID.Bytes())) | ||
147 | t.Logf("Expire: %d", hb.Expire_.Val) | ||
148 | t.Logf(" -> " + hb.Expire_.String()) | ||
149 | var exp util.AbsoluteTime | ||
150 | if err = data.Unmarshal(&exp, buf[32:40]); err != nil { | ||
151 | t.Fatal(err) | ||
152 | } | ||
153 | t.Logf(" -> " + exp.String()) | ||
154 | t.Log("AddrBin: " + hex.EncodeToString(hb.AddrBin)) | ||
155 | sd := hb.SignedData() | ||
156 | t.Log("SignedData: " + hex.EncodeToString(sd)) | ||
157 | t.Log("Addresses:") | ||
158 | for _, addr := range hb.Addresses() { | ||
159 | t.Logf("* " + addr.URI()) | ||
160 | } | ||
161 | t.Log("Signature: " + hex.EncodeToString(hb.Signature.Bytes())) | ||
162 | t.Fatal("debug HELLO verify failed") | ||
163 | } | ||
164 | } | ||
diff --git a/src/gnunet/service/dht/messages.go b/src/gnunet/service/dht/messages.go index 895d809..020c7f5 100644 --- a/src/gnunet/service/dht/messages.go +++ b/src/gnunet/service/dht/messages.go | |||
@@ -39,6 +39,7 @@ import ( | |||
39 | 39 | ||
40 | // HandleMessage handles a DHT request/response message. Responses are sent | 40 | // HandleMessage handles a DHT request/response message. Responses are sent |
41 | // to the specified responder. | 41 | // to the specified responder. |
42 | // | ||
42 | //nolint:gocyclo // life sometimes is complex... | 43 | //nolint:gocyclo // life sometimes is complex... |
43 | func (m *Module) HandleMessage(ctx context.Context, sender *util.PeerID, msgIn message.Message, back transport.Responder) bool { | 44 | func (m *Module) HandleMessage(ctx context.Context, sender *util.PeerID, msgIn message.Message, back transport.Responder) bool { |
44 | // assemble log label | 45 | // assemble log label |
@@ -69,12 +70,12 @@ func (m *Module) HandleMessage(ctx context.Context, sender *util.PeerID, msgIn m | |||
69 | 70 | ||
70 | //-------------------------------------------------------------- | 71 | //-------------------------------------------------------------- |
71 | // validate query (based on block type requested) (9.4.3.1) | 72 | // validate query (based on block type requested) (9.4.3.1) |
72 | btype := enums.BlockType(msg.BType) | 73 | btype := msg.BType |
73 | blockHdlr, ok := blocks.BlockHandlers[btype] | 74 | blockHdlr, ok := blocks.BlockHandlers[btype] |
74 | if ok { | 75 | if ok { |
75 | // validate block query | 76 | // validate block query |
76 | if !blockHdlr.ValidateBlockQuery(msg.Query, msg.XQuery) { | 77 | if !blockHdlr.ValidateBlockQuery(msg.Query, msg.XQuery) { |
77 | logger.Printf(logger.WARN, "[%s] invalid query -- discarded", label) | 78 | logger.Printf(logger.WARN, "[%s] invalid query -- message discarded", label) |
78 | return false | 79 | return false |
79 | } | 80 | } |
80 | } else { | 81 | } else { |
@@ -92,7 +93,8 @@ func (m *Module) HandleMessage(ctx context.Context, sender *util.PeerID, msgIn m | |||
92 | if blockHdlr != nil { | 93 | if blockHdlr != nil { |
93 | rf = blockHdlr.ParseResultFilter(msg.ResFilter) | 94 | rf = blockHdlr.ParseResultFilter(msg.ResFilter) |
94 | } else { | 95 | } else { |
95 | logger.Printf(logger.WARN, "[%s] unknown result filter implementation -- skipped", label) | 96 | logger.Printf(logger.WARN, "[%s] unknown result filter implementation -- message discarded", label) |
97 | return false | ||
96 | } | 98 | } |
97 | } else { | 99 | } else { |
98 | // ... or create a new one | 100 | // ... or create a new one |
@@ -145,7 +147,7 @@ func (m *Module) HandleMessage(ctx context.Context, sender *util.PeerID, msgIn m | |||
145 | } | 147 | } |
146 | } | 148 | } |
147 | // if we have results, send them as response on the back channel | 149 | // if we have results, send them as response on the back channel |
148 | rcv := "locally" | 150 | rcv := "local caller" |
149 | if back.Receiver() != nil { | 151 | if back.Receiver() != nil { |
150 | rcv = back.Receiver().Short() | 152 | rcv = back.Receiver().Short() |
151 | } | 153 | } |
@@ -176,7 +178,7 @@ func (m *Module) HandleMessage(ctx context.Context, sender *util.PeerID, msgIn m | |||
176 | // forward to number of peers | 178 | // forward to number of peers |
177 | numForward := m.rtable.ComputeOutDegree(msg.ReplLevel, msg.HopCount) | 179 | numForward := m.rtable.ComputeOutDegree(msg.ReplLevel, msg.HopCount) |
178 | for n := 0; n < numForward; n++ { | 180 | for n := 0; n < numForward; n++ { |
179 | if p := m.rtable.SelectClosestPeer(addr, pf, 0); p != nil { | 181 | if p := m.rtable.SelectPeer(addr, msg.HopCount, pf, 0); p != nil { |
180 | // forward message to peer | 182 | // forward message to peer |
181 | logger.Printf(logger.INFO, "[%s] forward GET message to %s", label, p.Peer.Short()) | 183 | logger.Printf(logger.INFO, "[%s] forward GET message to %s", label, p.Peer.Short()) |
182 | if err := m.core.Send(ctx, p.Peer, msgOut); err != nil { | 184 | if err := m.core.Send(ctx, p.Peer, msgOut); err != nil { |
@@ -309,7 +311,7 @@ func (m *Module) HandleMessage(ctx context.Context, sender *util.PeerID, msgIn m | |||
309 | // forward to computed number of peers | 311 | // forward to computed number of peers |
310 | numForward := m.rtable.ComputeOutDegree(msg.ReplLvl, msg.HopCount) | 312 | numForward := m.rtable.ComputeOutDegree(msg.ReplLvl, msg.HopCount) |
311 | for n := 0; n < numForward; n++ { | 313 | for n := 0; n < numForward; n++ { |
312 | if p := m.rtable.SelectClosestPeer(addr, pf, 0); p != nil { | 314 | if p := m.rtable.SelectPeer(addr, msg.HopCount, pf, 0); p != nil { |
313 | // check if route is recorded (9.3.2.6) | 315 | // check if route is recorded (9.3.2.6) |
314 | var pp *path.Path | 316 | var pp *path.Path |
315 | if msg.Flags&enums.DHT_RO_RECORD_ROUTE != 0 { | 317 | if msg.Flags&enums.DHT_RO_RECORD_ROUTE != 0 { |
@@ -353,7 +355,7 @@ func (m *Module) HandleMessage(ctx context.Context, sender *util.PeerID, msgIn m | |||
353 | return false | 355 | return false |
354 | } | 356 | } |
355 | //-------------------------------------------------------------- | 357 | //-------------------------------------------------------------- |
356 | btype := enums.BlockType(msg.BType) | 358 | btype := msg.BType |
357 | var blkKey *crypto.HashCode | 359 | var blkKey *crypto.HashCode |
358 | blockHdlr, ok := blocks.BlockHandlers[btype] | 360 | blockHdlr, ok := blocks.BlockHandlers[btype] |
359 | if ok { | 361 | if ok { |
diff --git a/src/gnunet/service/dht/module.go b/src/gnunet/service/dht/module.go index d33034e..fcf5d1c 100644 --- a/src/gnunet/service/dht/module.go +++ b/src/gnunet/service/dht/module.go | |||
@@ -72,7 +72,7 @@ func (lr *LocalBlockResponder) Send(ctx context.Context, msg message.Message) er | |||
72 | case *message.DHTP2PResultMsg: | 72 | case *message.DHTP2PResultMsg: |
73 | // deliver incoming blocks | 73 | // deliver incoming blocks |
74 | go func() { | 74 | go func() { |
75 | blk, err := blocks.NewBlock(enums.BlockType(res.BType), res.Expire, res.Block) | 75 | blk, err := blocks.NewBlock(res.BType, res.Expire, res.Block) |
76 | if err == nil { | 76 | if err == nil { |
77 | lr.ch <- blk | 77 | lr.ch <- blk |
78 | } else { | 78 | } else { |
@@ -80,7 +80,7 @@ func (lr *LocalBlockResponder) Send(ctx context.Context, msg message.Message) er | |||
80 | } | 80 | } |
81 | }() | 81 | }() |
82 | default: | 82 | default: |
83 | logger.Printf(logger.WARN, "[local] %d not a DHT-RESULT -- skipped", "") | 83 | logger.Printf(logger.WARN, "[local] %d not a DHT-RESULT -- skipped", msg.Type()) |
84 | } | 84 | } |
85 | return nil | 85 | return nil |
86 | } | 86 | } |
@@ -331,7 +331,7 @@ func (m *Module) event(ctx context.Context, ev *core.Event) { | |||
331 | } | 331 | } |
332 | } | 332 | } |
333 | 333 | ||
334 | //---------------------------------------------------------------------- | 334 | // ---------------------------------------------------------------------- |
335 | // Heartbeat handler for periodic tasks | 335 | // Heartbeat handler for periodic tasks |
336 | func (m *Module) heartbeat(ctx context.Context) { | 336 | func (m *Module) heartbeat(ctx context.Context) { |
337 | // run heartbeat for routing table | 337 | // run heartbeat for routing table |
@@ -368,7 +368,7 @@ func (m *Module) getHello(label string) (msg *message.DHTP2PHelloMsg, err error) | |||
368 | // assemble HELLO data | 368 | // assemble HELLO data |
369 | hb := new(blocks.HelloBlock) | 369 | hb := new(blocks.HelloBlock) |
370 | hb.PeerID = m.core.PeerID() | 370 | hb.PeerID = m.core.PeerID() |
371 | hb.Expire_ = util.NewAbsoluteTime(time.Now().Add(message.HelloAddressExpiration)) | 371 | hb.SetExpire(message.HelloAddressExpiration) |
372 | hb.SetAddresses(addrList) | 372 | hb.SetAddresses(addrList) |
373 | 373 | ||
374 | // sign HELLO block | 374 | // sign HELLO block |
diff --git a/src/gnunet/service/dht/path/elements.go b/src/gnunet/service/dht/path/elements.go index 1384469..4fb03c1 100644 --- a/src/gnunet/service/dht/path/elements.go +++ b/src/gnunet/service/dht/path/elements.go | |||
@@ -36,6 +36,7 @@ var ( | |||
36 | ) | 36 | ) |
37 | 37 | ||
38 | //---------------------------------------------------------------------- | 38 | //---------------------------------------------------------------------- |
39 | |||
39 | // Entry is an element of the path list | 40 | // Entry is an element of the path list |
40 | type Entry struct { | 41 | type Entry struct { |
41 | Signature *util.PeerSignature // path element signature | 42 | Signature *util.PeerSignature // path element signature |
@@ -57,9 +58,9 @@ func (e *Entry) String() string { | |||
57 | return fmt.Sprintf("(%s,%s)", e.Signer.String(), s) | 58 | return fmt.Sprintf("(%s,%s)", e.Signer.String(), s) |
58 | } | 59 | } |
59 | 60 | ||
60 | //---------------------------------------------------------------------- | 61 | // ---------------------------------------------------------------------- |
61 | // shared path element data across types | 62 | // shared path element data across types |
62 | type elementData struct { | 63 | type _ElementData struct { |
63 | Expire util.AbsoluteTime // expiration date | 64 | Expire util.AbsoluteTime // expiration date |
64 | BlockHash *crypto.HashCode // block hash | 65 | BlockHash *crypto.HashCode // block hash |
65 | PeerPredecessor *util.PeerID // predecessor peer | 66 | PeerPredecessor *util.PeerID // predecessor peer |
@@ -67,41 +68,48 @@ type elementData struct { | |||
67 | } | 68 | } |
68 | 69 | ||
69 | // helper type for signature creation/verification | 70 | // helper type for signature creation/verification |
70 | type elementSignedData struct { | 71 | type _SignedData struct { |
71 | Size uint16 `order:"big"` // size of signed data | 72 | Purpose *crypto.SignaturePurpose // signature purpose |
72 | Purpose uint16 `order:"big"` // signature purpose (SIG_DHT_HOP) | 73 | Elem *_ElementData // path element data |
73 | Elem *elementData `` // path element data | ||
74 | } | 74 | } |
75 | 75 | ||
76 | //---------------------------------------------------------------------- | 76 | // ---------------------------------------------------------------------- |
77 | // Element is the full-fledged data assembly for a path element in | 77 | // Element is the full-fledged data assembly for a path element in |
78 | // PUT/GET pathes. It is assembled programatically (on generation[1] and | 78 | // PUT/GET pathes. It is assembled programatically (on generation[1] and |
79 | // verification[2]) and not transferred in messages directly. | 79 | // verification[2]) and not transferred in messages directly. |
80 | // | 80 | // |
81 | // [1] spe = &Element{...} | 81 | // [1] spe = &Element{...} |
82 | // core.Sign(spe) | 82 | // |
83 | // msg.putpath[i] = spe.Wire() | 83 | // core.Sign(spe) |
84 | // msg.putpath[i] = spe.Wire() | ||
84 | // | 85 | // |
85 | // [2] pe = &Element{...,Signature: wire.sig} | 86 | // [2] pe = &Element{...,Signature: wire.sig} |
86 | // if !pe.Verify(peerId) { ... } | ||
87 | // | 87 | // |
88 | // if !pe.Verify(peerId) { ... } | ||
88 | type Element struct { | 89 | type Element struct { |
89 | elementData | 90 | _ElementData |
90 | Entry | 91 | Entry |
91 | } | 92 | } |
92 | 93 | ||
93 | // SignedData gets the data to be signed by peer ('Signable' interface) | 94 | // SignedData gets the data to be signed by peer ('Signable' interface) |
94 | func (pe *Element) SignedData() []byte { | 95 | func (pe *Element) SignedData() []byte { |
95 | sd := &elementSignedData{ | 96 | sd := &_SignedData{ |
96 | Size: 80, | 97 | Purpose: &crypto.SignaturePurpose{ |
97 | Purpose: uint16(enums.SIG_DHT_HOP), | 98 | Size: 144, |
98 | Elem: &(pe.elementData), | 99 | Purpose: enums.SIG_DHT_HOP, |
100 | }, | ||
101 | Elem: &(pe._ElementData), | ||
99 | } | 102 | } |
100 | buf, err := data.Marshal(sd) | 103 | buf, err := data.Marshal(sd) |
101 | if err != nil { | 104 | if err != nil { |
102 | logger.Println(logger.ERROR, "can't serialize path element for signature") | 105 | logger.Println(logger.ERROR, "can't serialize path element for signature") |
103 | return nil | 106 | return nil |
104 | } | 107 | } |
108 | if len(buf) != int(sd.Purpose.Size) { | ||
109 | logger.Printf(logger.ERROR, "size mismatch for serialized path element -- %d -> %d", sd.Purpose.Size, len(buf)) | ||
110 | sd.Purpose.Size = uint32(len(buf)) | ||
111 | return nil | ||
112 | } | ||
105 | return buf | 113 | return buf |
106 | } | 114 | } |
107 | 115 | ||
diff --git a/src/gnunet/service/dht/path/elements_test.go b/src/gnunet/service/dht/path/elements_test.go new file mode 100644 index 0000000..68c2384 --- /dev/null +++ b/src/gnunet/service/dht/path/elements_test.go | |||
@@ -0,0 +1,71 @@ | |||
1 | // This file is part of gnunet-go, a GNUnet-implementation in Golang. | ||
2 | // Copyright (C) 2019-2022 Bernd Fix >Y< | ||
3 | // | ||
4 | // gnunet-go is free software: you can redistribute it and/or modify it | ||
5 | // under the terms of the GNU Affero General Public License as published | ||
6 | // by the Free Software Foundation, either version 3 of the License, | ||
7 | // or (at your option) any later version. | ||
8 | // | ||
9 | // gnunet-go is distributed in the hope that it will be useful, but | ||
10 | // WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | // Affero General Public License for more details. | ||
13 | // | ||
14 | // You should have received a copy of the GNU Affero General Public License | ||
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | // | ||
17 | // SPDX-License-Identifier: AGPL3.0-or-later | ||
18 | |||
19 | package path | ||
20 | |||
21 | import ( | ||
22 | "encoding/hex" | ||
23 | "gnunet/util" | ||
24 | "testing" | ||
25 | ) | ||
26 | |||
27 | func TestElementDebug(t *testing.T) { | ||
28 | var ( | ||
29 | signedData = "" + | ||
30 | "00000090" + | ||
31 | "00000006" + | ||
32 | "0005e6983d33f911" + | ||
33 | "f3236acc2be7812a988617c647fc27fcfbd0dacc3d960aa29a5f9bf0b9b9131f" + | ||
34 | "cdd31cfa45de2cbd9510665e7f2b1ccafefd445511c62729c0798dd1b0675f19" + | ||
35 | "0000000000000000000000000000000000000000000000000000000000000000" + | ||
36 | "23b096021b25d822c217a756b877cf72c7fdabd4eff79c4dbb7418dd2b232386" | ||
37 | |||
38 | signature = "" + | ||
39 | "ef94ddfd90b56f30b265a88384551907fadef176b4ba6b023df429506b34cde0" + | ||
40 | "39f38661d451e6e5bd1c4d5d078d27f0e8954bd964ea55f03afa42aa9964cc0c" | ||
41 | signer = "" + | ||
42 | "28f06fe5178742c3b8f080431e48cf5bf3898ba8b8fd57a975772d14003a8c75" | ||
43 | predecessor = "" + | ||
44 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
45 | successor = "" + | ||
46 | "23b096021b25d822c217a756b877cf72c7fdabd4eff79c4dbb7418dd2b232386" | ||
47 | ) | ||
48 | convert := func(s string) []byte { | ||
49 | buf, err := hex.DecodeString(s) | ||
50 | if err != nil { | ||
51 | t.Fatal(err) | ||
52 | } | ||
53 | return buf | ||
54 | } | ||
55 | sd := convert(signedData) | ||
56 | sig := util.NewPeerSignature(convert(signature)) | ||
57 | pred := util.NewPeerID(convert(predecessor)) | ||
58 | curr := util.NewPeerID(convert(signer)) | ||
59 | succ := util.NewPeerID(convert(successor)) | ||
60 | |||
61 | ok, err := curr.Verify(sd, sig) | ||
62 | if err != nil { | ||
63 | t.Fatal(err) | ||
64 | } | ||
65 | if !ok { | ||
66 | t.Logf("Pred: %s", pred.Short()) | ||
67 | t.Logf("Sign: %s", curr.Short()) | ||
68 | t.Logf("Succ: %s", succ.Short()) | ||
69 | t.Error("Verify NOT OK:") | ||
70 | } | ||
71 | } | ||
diff --git a/src/gnunet/service/dht/path/handling.go b/src/gnunet/service/dht/path/handling.go index 4040511..7ad91df 100644 --- a/src/gnunet/service/dht/path/handling.go +++ b/src/gnunet/service/dht/path/handling.go | |||
@@ -19,11 +19,10 @@ | |||
19 | package path | 19 | package path |
20 | 20 | ||
21 | import ( | 21 | import ( |
22 | "bytes" | ||
23 | "encoding/hex" | ||
24 | "fmt" | ||
25 | "gnunet/crypto" | 22 | "gnunet/crypto" |
23 | "gnunet/enums" | ||
26 | "gnunet/util" | 24 | "gnunet/util" |
25 | "strings" | ||
27 | 26 | ||
28 | "github.com/bfix/gospel/data" | 27 | "github.com/bfix/gospel/data" |
29 | "github.com/bfix/gospel/logger" | 28 | "github.com/bfix/gospel/logger" |
@@ -33,17 +32,11 @@ import ( | |||
33 | // Path handling | 32 | // Path handling |
34 | //---------------------------------------------------------------------- | 33 | //---------------------------------------------------------------------- |
35 | 34 | ||
36 | // path flags | ||
37 | const ( | ||
38 | PathTruncated = 1 | ||
39 | PathLastHop = 2 | ||
40 | ) | ||
41 | |||
42 | // Path is the complete list of verified hops a message travelled. | 35 | // Path is the complete list of verified hops a message travelled. |
43 | // It also keeps the associated block hash and expiration time of | 36 | // It also keeps the associated block hash and expiration time of |
44 | // the request for signature verification purposes. | 37 | // the request for signature verification purposes. |
45 | type Path struct { | 38 | type Path struct { |
46 | Flags uint32 `order:"big"` // flags | 39 | Flags uint16 `order:"big"` // flags |
47 | BlkHash *crypto.HashCode `` // block hash value | 40 | BlkHash *crypto.HashCode `` // block hash value |
48 | Expire util.AbsoluteTime `` // expiration time | 41 | Expire util.AbsoluteTime `` // expiration time |
49 | TruncOrigin *util.PeerID `opt:"(IsUsed)"` // truncated origin (optional) | 42 | TruncOrigin *util.PeerID `opt:"(IsUsed)"` // truncated origin (optional) |
@@ -58,9 +51,9 @@ type Path struct { | |||
58 | func (p *Path) IsUsed(field string) bool { | 51 | func (p *Path) IsUsed(field string) bool { |
59 | switch field { | 52 | switch field { |
60 | case "TruncOrigin": | 53 | case "TruncOrigin": |
61 | return p.Flags&PathTruncated != 0 | 54 | return p.Flags&enums.DHT_RO_TRUNCATED != 0 |
62 | case "LastSig", "LastHop": | 55 | case "LastSig", "LastHop": |
63 | return p.Flags&PathLastHop != 0 | 56 | return p.Flags&enums.DHT_RO_RECORD_ROUTE != 0 |
64 | } | 57 | } |
65 | return false | 58 | return false |
66 | } | 59 | } |
@@ -128,7 +121,7 @@ func (p *Path) Clone() *Path { | |||
128 | // NewElement creates a new path element from data | 121 | // NewElement creates a new path element from data |
129 | func (p *Path) NewElement(pred, signer, succ *util.PeerID) *Element { | 122 | func (p *Path) NewElement(pred, signer, succ *util.PeerID) *Element { |
130 | return &Element{ | 123 | return &Element{ |
131 | elementData: elementData{ | 124 | _ElementData: _ElementData{ |
132 | Expire: p.Expire, | 125 | Expire: p.Expire, |
133 | BlockHash: p.BlkHash, | 126 | BlockHash: p.BlkHash, |
134 | PeerPredecessor: pred, | 127 | PeerPredecessor: pred, |
@@ -155,7 +148,7 @@ func (p *Path) Add(elem *Element) { | |||
155 | // update last hop signature | 148 | // update last hop signature |
156 | p.LastSig = elem.Signature | 149 | p.LastSig = elem.Signature |
157 | p.LastHop = elem.Signer | 150 | p.LastHop = elem.Signer |
158 | p.Flags |= PathLastHop | 151 | p.Flags |= enums.DHT_RO_RECORD_ROUTE |
159 | } | 152 | } |
160 | 153 | ||
161 | // Verify path: process list entries from right to left (decreasing index). | 154 | // Verify path: process list entries from right to left (decreasing index). |
@@ -181,6 +174,7 @@ func (p *Path) Verify(local *util.PeerID) { | |||
181 | pe := p.NewElement(pred, p.LastHop, local) | 174 | pe := p.NewElement(pred, p.LastHop, local) |
182 | ok, err := pe.Verify(p.LastSig) | 175 | ok, err := pe.Verify(p.LastSig) |
183 | if err != nil || !ok { | 176 | if err != nil || !ok { |
177 | logger.Println(logger.WARN, "[path] Dropping path (invalid last signature)") | ||
184 | // remove last hop signature and truncated origin; reset flags | 178 | // remove last hop signature and truncated origin; reset flags |
185 | p.LastSig = nil | 179 | p.LastSig = nil |
186 | p.LastHop = nil | 180 | p.LastHop = nil |
@@ -188,79 +182,79 @@ func (p *Path) Verify(local *util.PeerID) { | |||
188 | p.Flags = 0 | 182 | p.Flags = 0 |
189 | } | 183 | } |
190 | return | 184 | return |
191 | } else { | 185 | } |
192 | // yes: process list of path elements | 186 | // yes: process list of path elements |
193 | signer := p.LastHop | 187 | signer := p.LastHop |
194 | sig := p.LastSig | 188 | sig := p.LastSig |
195 | succ := local | 189 | succ := local |
196 | num := len(p.List) | 190 | num := len(p.List) |
197 | var pred *util.PeerID | 191 | var pred *util.PeerID |
198 | for i := num - 1; i >= 0; i-- { | 192 | for i := num - 1; i >= 0; i-- { |
199 | if i == -1 { | 193 | if i == -1 { |
200 | if p.TruncOrigin != nil { | 194 | if p.TruncOrigin != nil { |
201 | pred = p.TruncOrigin | 195 | pred = p.TruncOrigin |
202 | } else { | ||
203 | pred = util.NewPeerID(nil) | ||
204 | } | ||
205 | } else { | 196 | } else { |
206 | pred = p.List[i].Signer | 197 | pred = util.NewPeerID(nil) |
207 | } | 198 | } |
208 | pe := p.NewElement(pred, signer, succ) | 199 | } else { |
209 | ok, err := pe.Verify(sig) | 200 | pred = p.List[i].Signer |
210 | if err != nil || !ok { | 201 | } |
211 | // we need to truncate: | 202 | pe := p.NewElement(pred, signer, succ) |
212 | logger.Printf(logger.WARN, "[path] Truncating path (invalid signature at hop %d)", i) | 203 | ok, err := pe.Verify(sig) |
204 | if err != nil || !ok { | ||
205 | // we need to truncate: | ||
206 | logger.Printf(logger.WARN, "[path] Truncating path (invalid signature at hop %d)", i) | ||
213 | 207 | ||
214 | // are we at the end of the list? | 208 | // are we at the end of the list? |
215 | if i == num-1 { | 209 | if i == num-1 { |
216 | // yes: the last hop signature failed -> reset path | 210 | // yes: the last hop signature failed -> reset path |
217 | p.LastSig = nil | 211 | p.LastSig = nil |
218 | p.LastHop = nil | 212 | p.LastHop = nil |
219 | p.TruncOrigin = nil | 213 | p.TruncOrigin = nil |
220 | p.Flags = 0 | 214 | p.Flags = 0 |
221 | p.List = make([]*Entry, 0) | 215 | p.List = make([]*Entry, 0) |
222 | return | ||
223 | } | ||
224 | // trim list | ||
225 | p.Flags |= PathTruncated | ||
226 | p.TruncOrigin = signer | ||
227 | size := num - 2 - i | ||
228 | list := make([]*Entry, size) | ||
229 | if size > 0 { | ||
230 | copy(list, p.List[i+2:]) | ||
231 | } | ||
232 | p.List = list | ||
233 | return | 216 | return |
234 | } | 217 | } |
235 | // check next path element | 218 | // trim list |
236 | succ = signer | 219 | p.Flags |= enums.DHT_RO_TRUNCATED |
237 | signer = pred | 220 | p.TruncOrigin = signer |
238 | if i != -1 { | 221 | size := num - 2 - i |
239 | sig = p.List[i].Signature | 222 | list := make([]*Entry, size) |
223 | if size > 0 { | ||
224 | copy(list, p.List[i+2:]) | ||
240 | } | 225 | } |
226 | p.List = list | ||
227 | return | ||
228 | } | ||
229 | // check next path element | ||
230 | succ = signer | ||
231 | signer = pred | ||
232 | if i != -1 { | ||
233 | sig = p.List[i].Signature | ||
241 | } | 234 | } |
242 | } | 235 | } |
243 | } | 236 | } |
244 | 237 | ||
245 | // String returs a uman-readbale representation | 238 | // String returns a human-readable representation |
246 | func (p *Path) String() string { | 239 | func (p *Path) String() string { |
247 | buf := new(bytes.Buffer) | 240 | var hops []string |
248 | s := "0" | 241 | if p != nil { |
249 | if p.TruncOrigin != nil { | 242 | if p.TruncOrigin != nil { |
250 | s = p.TruncOrigin.String() | 243 | hops = append(hops, p.TruncOrigin.Short()) |
251 | } | 244 | } |
252 | buf.WriteString(fmt.Sprintf("{to=%s, (%d)[", s, len(p.List))) | 245 | for _, e := range p.List { |
253 | for _, e := range p.List { | 246 | hops = append(hops, e.Signer.Short()) |
254 | buf.WriteString(e.String()) | 247 | } |
255 | } | 248 | if p.LastHop != nil { |
256 | s = "0" | 249 | hops = append(hops, p.LastHop.Short()) |
257 | if p.LastSig != nil { | 250 | } |
258 | s = hex.EncodeToString(p.LastSig.Bytes()) | ||
259 | } | 251 | } |
260 | num := len(s) | 252 | // trim to sensible length for display |
261 | if num > 16 { | 253 | if num := len(hops); num > 8 { |
262 | s = s[:8] + ".." + s[num-8:] | 254 | trim := make([]string, 9) |
255 | copy(trim[:4], hops[:4]) | ||
256 | trim[4] = "..." | ||
257 | copy(trim[5:], hops[num-5:]) | ||
263 | } | 258 | } |
264 | buf.WriteString(fmt.Sprintf("], ls=%s}", s)) | 259 | return "[" + strings.Join(hops, "-") + "]" |
265 | return buf.String() | ||
266 | } | 260 | } |
diff --git a/src/gnunet/service/dht/resulthandler.go b/src/gnunet/service/dht/resulthandler.go index 7df405b..7d9a94f 100644 --- a/src/gnunet/service/dht/resulthandler.go +++ b/src/gnunet/service/dht/resulthandler.go | |||
@@ -45,6 +45,7 @@ import ( | |||
45 | //====================================================================== | 45 | //====================================================================== |
46 | 46 | ||
47 | // Compare return values | 47 | // Compare return values |
48 | // | ||
48 | //nolint:stylecheck // allow non-camel-case in constants | 49 | //nolint:stylecheck // allow non-camel-case in constants |
49 | const ( | 50 | const ( |
50 | RHC_SAME = blocks.CMP_SAME // the two result handlers are the same | 51 | RHC_SAME = blocks.CMP_SAME // the two result handlers are the same |
@@ -135,7 +136,7 @@ func (t *ResultHandler) Merge(a *ResultHandler) bool { | |||
135 | 136 | ||
136 | // Proceed return true if the message is to be processed in derived implementations | 137 | // Proceed return true if the message is to be processed in derived implementations |
137 | func (t *ResultHandler) Proceed(ctx context.Context, msg *message.DHTP2PResultMsg) bool { | 138 | func (t *ResultHandler) Proceed(ctx context.Context, msg *message.DHTP2PResultMsg) bool { |
138 | blk, err := blocks.NewBlock(enums.BlockType(msg.BType), msg.Expire, msg.Block) | 139 | blk, err := blocks.NewBlock(msg.BType, msg.Expire, msg.Block) |
139 | if err == nil && !t.resFilter.Contains(blk) { | 140 | if err == nil && !t.resFilter.Contains(blk) { |
140 | t.resFilter.Add(blk) | 141 | t.resFilter.Add(blk) |
141 | return true | 142 | return true |
diff --git a/src/gnunet/service/dht/routingtable.go b/src/gnunet/service/dht/routingtable.go index 21c8823..aa3c32f 100644 --- a/src/gnunet/service/dht/routingtable.go +++ b/src/gnunet/service/dht/routingtable.go | |||
@@ -206,7 +206,7 @@ func (rt *RoutingTable) Contains(p *PeerAddress, label string) bool { | |||
206 | list = append(list, val.Peer.Short()) | 206 | list = append(list, val.Peer.Short()) |
207 | return nil | 207 | return nil |
208 | }, true) | 208 | }, true) |
209 | logger.Printf(logger.DBG, "[%s] RT=%v", list) | 209 | logger.Printf(logger.DBG, "[%s] RT=%v", label, list) |
210 | } else { | 210 | } else { |
211 | //logger.Println(logger.DBG, "[RT] --> found in current list") | 211 | //logger.Println(logger.DBG, "[RT] --> found in current list") |
212 | px.lastSeen = util.AbsoluteTimeNow() | 212 | px.lastSeen = util.AbsoluteTimeNow() |
@@ -280,7 +280,7 @@ func (rt *RoutingTable) SelectRandomPeer(pf *blocks.PeerFilter, pid int) (p *Pee | |||
280 | // SelectPeer selects a neighbor depending on the number of hops parameter. | 280 | // SelectPeer selects a neighbor depending on the number of hops parameter. |
281 | // If hops < NSE this function MUST return SelectRandomPeer() and | 281 | // If hops < NSE this function MUST return SelectRandomPeer() and |
282 | // SelectClosestpeer() otherwise. | 282 | // SelectClosestpeer() otherwise. |
283 | func (rt *RoutingTable) SelectPeer(p *PeerAddress, hops int, bf *blocks.PeerFilter, pid int) *PeerAddress { | 283 | func (rt *RoutingTable) SelectPeer(p *PeerAddress, hops uint16, bf *blocks.PeerFilter, pid int) *PeerAddress { |
284 | if float64(hops) < rt.l2nse { | 284 | if float64(hops) < rt.l2nse { |
285 | return rt.SelectRandomPeer(bf, pid) | 285 | return rt.SelectRandomPeer(bf, pid) |
286 | } | 286 | } |
@@ -386,7 +386,7 @@ func (rt *RoutingTable) LookupHello(addr *PeerAddress, rf blocks.ResultFilter, a | |||
386 | results = append(results, result) | 386 | results = append(results, result) |
387 | } | 387 | } |
388 | } else { | 388 | } else { |
389 | logger.Printf(logger.DBG, "[%s] LookupHello: cached HELLO block is filtered") | 389 | logger.Println(logger.DBG, "[%s] LookupHello: cached HELLO block is filtered") |
390 | } | 390 | } |
391 | return nil | 391 | return nil |
392 | }, true) | 392 | }, true) |
diff --git a/src/gnunet/service/gns/module.go b/src/gnunet/service/gns/module.go index 02d69a1..f12a89a 100644 --- a/src/gnunet/service/gns/module.go +++ b/src/gnunet/service/gns/module.go | |||
@@ -200,6 +200,7 @@ func (m *Module) ResolveAbsolute( | |||
200 | // ResolveRelative resolves a relative path (to a given zone) recursively by | 200 | // ResolveRelative resolves a relative path (to a given zone) recursively by |
201 | // processing simple (PKEY,Label) lookups in sequence and handle intermediate | 201 | // processing simple (PKEY,Label) lookups in sequence and handle intermediate |
202 | // GNS record types | 202 | // GNS record types |
203 | // | ||
203 | //nolint:gocyclo // life sometimes is complex... | 204 | //nolint:gocyclo // life sometimes is complex... |
204 | func (m *Module) ResolveRelative( | 205 | func (m *Module) ResolveRelative( |
205 | ctx context.Context, | 206 | ctx context.Context, |
diff --git a/src/gnunet/service/gns/service.go b/src/gnunet/service/gns/service.go index fb6aea0..010c460 100644 --- a/src/gnunet/service/gns/service.go +++ b/src/gnunet/service/gns/service.go | |||
@@ -278,7 +278,7 @@ func (s *Service) LookupNamecache(ctx context.Context, query *blocks.GNSQuery) ( | |||
278 | block.DerivedKeySig = m.DerivedKeySig | 278 | block.DerivedKeySig = m.DerivedKeySig |
279 | sb := new(blocks.SignedGNSBlockData) | 279 | sb := new(blocks.SignedGNSBlockData) |
280 | sb.Purpose = new(crypto.SignaturePurpose) | 280 | sb.Purpose = new(crypto.SignaturePurpose) |
281 | sb.Purpose.Purpose = uint32(enums.SIG_GNS_RECORD_SIGN) | 281 | sb.Purpose.Purpose = enums.SIG_GNS_RECORD_SIGN |
282 | sb.Purpose.Size = uint32(16 + len(m.EncData)) | 282 | sb.Purpose.Size = uint32(16 + len(m.EncData)) |
283 | sb.Expire = m.Expire | 283 | sb.Expire = m.Expire |
284 | sb.Data = m.EncData | 284 | sb.Data = m.EncData |
@@ -413,7 +413,7 @@ func (s *Service) LookupDHT(ctx context.Context, query blocks.Query) (block bloc | |||
413 | break | 413 | break |
414 | } | 414 | } |
415 | // check if result is of requested type | 415 | // check if result is of requested type |
416 | if enums.BlockType(m.BType) != enums.BLOCK_TYPE_GNS_NAMERECORD { | 416 | if m.BType != enums.BLOCK_TYPE_GNS_NAMERECORD { |
417 | logger.Println(logger.ERROR, "[gns] DHT response has wrong type") | 417 | logger.Println(logger.ERROR, "[gns] DHT response has wrong type") |
418 | break | 418 | break |
419 | } | 419 | } |
diff --git a/src/gnunet/service/module.go b/src/gnunet/service/module.go index d09d41e..8160e39 100644 --- a/src/gnunet/service/module.go +++ b/src/gnunet/service/module.go | |||
@@ -24,7 +24,7 @@ import ( | |||
24 | "time" | 24 | "time" |
25 | ) | 25 | ) |
26 | 26 | ||
27 | //---------------------------------------------------------------------- | 27 | // ---------------------------------------------------------------------- |
28 | // Module is an interface for GNUnet service modules (workers). | 28 | // Module is an interface for GNUnet service modules (workers). |
29 | // | 29 | // |
30 | // Modules can call other GNUnet services; these services can be used by | 30 | // Modules can call other GNUnet services; these services can be used by |
@@ -34,29 +34,28 @@ import ( | |||
34 | // calls to m.Export() and m.Import() to link the modules together (see | 34 | // calls to m.Export() and m.Import() to link the modules together (see |
35 | // example): | 35 | // example): |
36 | // | 36 | // |
37 | // // create module instances | 37 | // // create module instances |
38 | // gnsMod = gns.NewModule(ctx, core) | 38 | // gnsMod = gns.NewModule(ctx, core) |
39 | // dhtMod = dht.NewModule(ctx, core) | 39 | // dhtMod = dht.NewModule(ctx, core) |
40 | // ncMod = namecache.NewModule(ctx, core) | 40 | // ncMod = namecache.NewModule(ctx, core) |
41 | // revMod = revocation.NewModule(ctx, core) | 41 | // revMod = revocation.NewModule(ctx, core) |
42 | // | 42 | // |
43 | // // export module functions | 43 | // // export module functions |
44 | // fcn := make(map[string]any) | 44 | // fcn := make(map[string]any) |
45 | // gnsMod.Export(fcn) | 45 | // gnsMod.Export(fcn) |
46 | // dhtMod.Export(fcn) | 46 | // dhtMod.Export(fcn) |
47 | // ncMod.Export(fcn) | 47 | // ncMod.Export(fcn) |
48 | // revMod.Export(fcn) | 48 | // revMod.Export(fcn) |
49 | // | 49 | // |
50 | // // import (link) module functions | 50 | // // import (link) module functions |
51 | // gnsMod.Import(fcn) | 51 | // gnsMod.Import(fcn) |
52 | // dhtMod.Import(fcn) | 52 | // dhtMod.Import(fcn) |
53 | // ncMod.Import(fcn) | 53 | // ncMod.Import(fcn) |
54 | // revMod.Import(fcn) | 54 | // revMod.Import(fcn) |
55 | // | 55 | // |
56 | // Exported and imported module function are identified by name defined in the | 56 | // Exported and imported module function are identified by name defined in the |
57 | // Export() function. Import() functions that access functions in other modules | 57 | // Export() function. Import() functions that access functions in other modules |
58 | // need to use the same name for linking. | 58 | // need to use the same name for linking. |
59 | // | ||
60 | type Module interface { | 59 | type Module interface { |
61 | // Export functions by name | 60 | // Export functions by name |
62 | Export(map[string]any) | 61 | Export(map[string]any) |
diff --git a/src/gnunet/service/revocation/pow.go b/src/gnunet/service/revocation/pow.go index 5518749..1c67c23 100644 --- a/src/gnunet/service/revocation/pow.go +++ b/src/gnunet/service/revocation/pow.go | |||
@@ -148,7 +148,7 @@ func (rd *RevData) Sign(skey *crypto.ZonePrivate) (err error) { | |||
148 | sigBlock := &SignedRevData{ | 148 | sigBlock := &SignedRevData{ |
149 | Purpose: &crypto.SignaturePurpose{ | 149 | Purpose: &crypto.SignaturePurpose{ |
150 | Size: uint32(20 + rd.ZoneKeySig.KeySize()), | 150 | Size: uint32(20 + rd.ZoneKeySig.KeySize()), |
151 | Purpose: uint32(enums.SIG_REVOCATION), | 151 | Purpose: enums.SIG_REVOCATION, |
152 | }, | 152 | }, |
153 | Timestamp: rd.Timestamp, | 153 | Timestamp: rd.Timestamp, |
154 | ZoneKey: &rd.ZoneKeySig.ZoneKey, | 154 | ZoneKey: &rd.ZoneKeySig.ZoneKey, |
@@ -169,7 +169,7 @@ func (rd *RevData) Verify(withSig bool) (zbits float64, rc int) { | |||
169 | sigBlock := &SignedRevData{ | 169 | sigBlock := &SignedRevData{ |
170 | Purpose: &crypto.SignaturePurpose{ | 170 | Purpose: &crypto.SignaturePurpose{ |
171 | Size: uint32(20 + rd.ZoneKeySig.KeySize()), | 171 | Size: uint32(20 + rd.ZoneKeySig.KeySize()), |
172 | Purpose: uint32(enums.SIG_REVOCATION), | 172 | Purpose: enums.SIG_REVOCATION, |
173 | }, | 173 | }, |
174 | Timestamp: rd.Timestamp, | 174 | Timestamp: rd.Timestamp, |
175 | ZoneKey: &rd.ZoneKeySig.ZoneKey, | 175 | ZoneKey: &rd.ZoneKeySig.ZoneKey, |
diff --git a/src/gnunet/service/revocation/pow_test.go b/src/gnunet/service/revocation/pow_test.go index 5d31b2f..0747d72 100644 --- a/src/gnunet/service/revocation/pow_test.go +++ b/src/gnunet/service/revocation/pow_test.go | |||
@@ -117,7 +117,7 @@ func TestRevocationRFC(t *testing.T) { | |||
117 | sigBlock := &SignedRevData{ | 117 | sigBlock := &SignedRevData{ |
118 | Purpose: &crypto.SignaturePurpose{ | 118 | Purpose: &crypto.SignaturePurpose{ |
119 | Size: uint32(20 + revData.ZoneKeySig.KeySize()), | 119 | Size: uint32(20 + revData.ZoneKeySig.KeySize()), |
120 | Purpose: uint32(enums.SIG_REVOCATION), | 120 | Purpose: enums.SIG_REVOCATION, |
121 | }, | 121 | }, |
122 | Timestamp: revData.Timestamp, | 122 | Timestamp: revData.Timestamp, |
123 | ZoneKey: &revData.ZoneKeySig.ZoneKey, | 123 | ZoneKey: &revData.ZoneKeySig.ZoneKey, |
diff --git a/src/gnunet/service/rpc.go b/src/gnunet/service/rpc.go index d5740fb..0554db6 100644 --- a/src/gnunet/service/rpc.go +++ b/src/gnunet/service/rpc.go | |||
@@ -54,10 +54,11 @@ func RunRPCServer(ctx context.Context, endpoint string) (srvRPC *JRPCServer, err | |||
54 | 54 | ||
55 | // instantiate a server and run it | 55 | // instantiate a server and run it |
56 | srv := &http.Server{ | 56 | srv := &http.Server{ |
57 | Handler: router, | 57 | Handler: router, |
58 | Addr: endpoint, | 58 | Addr: endpoint, |
59 | WriteTimeout: 15 * time.Second, | 59 | WriteTimeout: 5 * time.Second, |
60 | ReadTimeout: 15 * time.Second, | 60 | ReadTimeout: 15 * time.Second, |
61 | ReadHeaderTimeout: 5 * time.Second, | ||
61 | } | 62 | } |
62 | // start listening | 63 | // start listening |
63 | go func() { | 64 | go func() { |
diff --git a/src/gnunet/service/store/database.go b/src/gnunet/service/store/database.go index 1f25d80..4dfbf2a 100644 --- a/src/gnunet/service/store/database.go +++ b/src/gnunet/service/store/database.go | |||
@@ -132,11 +132,11 @@ func (p *dbPool) remove(key string) error { | |||
132 | // argument defines the SQL database type. Other arguments depend on the value | 132 | // argument defines the SQL database type. Other arguments depend on the value |
133 | // of this first argument. | 133 | // of this first argument. |
134 | // The following SQL types are implemented: | 134 | // The following SQL types are implemented: |
135 | // * 'sqlite3': SQLite3-compatible database; the second argument specifies the | 135 | // - 'sqlite3': SQLite3-compatible database; the second argument specifies the |
136 | // file that holds the data (e.g. "sqlite3+/home/user/store.db") | 136 | // file that holds the data (e.g. "sqlite3+/home/user/store.db") |
137 | // * 'mysql': A MySQL-compatible database; the second argument specifies the | 137 | // - 'mysql': A MySQL-compatible database; the second argument specifies the |
138 | // information required to log into the database (e.g. | 138 | // information required to log into the database (e.g. |
139 | // "[user[:passwd]@][proto[(addr)]]/dbname[?param1=value1&...]"). | 139 | // "[user[:passwd]@][proto[(addr)]]/dbname[?param1=value1&...]"). |
140 | func (p *dbPool) Connect(spec string) (db *DBConn, err error) { | 140 | func (p *dbPool) Connect(spec string) (db *DBConn, err error) { |
141 | err = p.insts.Process(func(pid int) error { | 141 | err = p.insts.Process(func(pid int) error { |
142 | // check if we have a connection to this database. | 142 | // check if we have a connection to this database. |
diff --git a/src/gnunet/service/store/store_dht.go b/src/gnunet/service/store/store_dht.go index 54246db..3e0eb29 100644 --- a/src/gnunet/service/store/store_dht.go +++ b/src/gnunet/service/store/store_dht.go | |||
@@ -166,12 +166,9 @@ func (s *DHTStore) Put(query blocks.Query, entry *DHTEntry) (err error) { | |||
166 | btype := query.Type() | 166 | btype := query.Type() |
167 | expire := entry.Blk.Expire() | 167 | expire := entry.Blk.Expire() |
168 | blkSize := len(entry.Blk.Bytes()) | 168 | blkSize := len(entry.Blk.Bytes()) |
169 | pl := 0 | 169 | |
170 | if entry.Path != nil { | 170 | logger.Printf(logger.INFO, "[dht-store] storing %d bytes @ %s (path %s)", |
171 | pl = int(entry.Path.NumList) | 171 | blkSize, query.Key().Short(), entry.Path) |
172 | } | ||
173 | logger.Printf(logger.INFO, "[dht-store] storing %d bytes under key %s (path: %d)", | ||
174 | blkSize, query.Key().Short(), pl) | ||
175 | 172 | ||
176 | // write entry to file for storage | 173 | // write entry to file for storage |
177 | if err = s.writeEntry(query.Key().Data, entry); err != nil { | 174 | if err = s.writeEntry(query.Key().Data, entry); err != nil { |
@@ -276,7 +273,7 @@ func (s *DHTStore) GetApprox(label string, query blocks.Query, rf blocks.ResultF | |||
276 | 273 | ||
277 | //---------------------------------------------------------------------- | 274 | //---------------------------------------------------------------------- |
278 | 275 | ||
279 | type entryLayout struct { | 276 | type _EntryLayout struct { |
280 | SizeBlk uint16 `order:"big"` // size of block data | 277 | SizeBlk uint16 `order:"big"` // size of block data |
281 | SizePth uint16 `order:"big"` // size of path data | 278 | SizePth uint16 `order:"big"` // size of path data |
282 | Block []byte `size:"SizeBlk"` // block data | 279 | Block []byte `size:"SizeBlk"` // block data |
@@ -300,7 +297,7 @@ func (s *DHTStore) readEntry(md *FileMetadata) (entry *DHTEntry, err error) { | |||
300 | size := int(fi.Size()) | 297 | size := int(fi.Size()) |
301 | 298 | ||
302 | // read data | 299 | // read data |
303 | val := new(entryLayout) | 300 | val := new(_EntryLayout) |
304 | if err = data.UnmarshalStream(file, val, size); err != nil { | 301 | if err = data.UnmarshalStream(file, val, size); err != nil { |
305 | return | 302 | return |
306 | } | 303 | } |
@@ -329,7 +326,7 @@ func (s *DHTStore) writeEntry(key []byte, entry *DHTEntry) (err error) { | |||
329 | defer file.Close() | 326 | defer file.Close() |
330 | 327 | ||
331 | // assemble and write entry | 328 | // assemble and write entry |
332 | val := new(entryLayout) | 329 | val := new(_EntryLayout) |
333 | val.Block = entry.Blk.Bytes() | 330 | val.Block = entry.Blk.Bytes() |
334 | val.SizeBlk = uint16(len(val.Block)) | 331 | val.SizeBlk = uint16(len(val.Block)) |
335 | if entry.Path != nil { | 332 | if entry.Path != nil { |
diff --git a/src/gnunet/service/store/store_dht_meta.go b/src/gnunet/service/store/store_dht_meta.go index 5075d90..3564328 100644 --- a/src/gnunet/service/store/store_dht_meta.go +++ b/src/gnunet/service/store/store_dht_meta.go | |||
@@ -70,8 +70,8 @@ type FileMetaDB struct { | |||
70 | // database is "access.db". | 70 | // database is "access.db". |
71 | func OpenMetaDB(path string) (db *FileMetaDB, err error) { | 71 | func OpenMetaDB(path string) (db *FileMetaDB, err error) { |
72 | // connect to database | 72 | // connect to database |
73 | dbFile := path + "/acccess.db" | 73 | dbFile := path + "/access.db" |
74 | if _, err = os.Stat(path + "/acccess.db"); err != nil { | 74 | if _, err = os.Stat(path + "/access.db"); err != nil { |
75 | var file *os.File | 75 | var file *os.File |
76 | if file, err = os.Create(dbFile); err != nil { | 76 | if file, err = os.Create(dbFile); err != nil { |
77 | return | 77 | return |
diff --git a/src/gnunet/service/store/store_kv.go b/src/gnunet/service/store/store_kv.go index 8bcb711..4d2cb71 100644 --- a/src/gnunet/service/store/store_kv.go +++ b/src/gnunet/service/store/store_kv.go | |||
@@ -56,7 +56,7 @@ type KVStore interface { | |||
56 | Close() error | 56 | Close() error |
57 | } | 57 | } |
58 | 58 | ||
59 | //------------------------------------------------------------ | 59 | // ------------------------------------------------------------ |
60 | // NewKVStore creates a new storage handler with given spec | 60 | // NewKVStore creates a new storage handler with given spec |
61 | // for use with key/value string pairs. | 61 | // for use with key/value string pairs. |
62 | func NewKVStore(spec util.ParameterSet) (KVStore, error) { | 62 | func NewKVStore(spec util.ParameterSet) (KVStore, error) { |
diff --git a/src/gnunet/transport/responder.go b/src/gnunet/transport/responder.go index be958bf..3ed191a 100644 --- a/src/gnunet/transport/responder.go +++ b/src/gnunet/transport/responder.go | |||
@@ -25,7 +25,7 @@ import ( | |||
25 | "gnunet/util" | 25 | "gnunet/util" |
26 | ) | 26 | ) |
27 | 27 | ||
28 | //---------------------------------------------------------------------- | 28 | // ---------------------------------------------------------------------- |
29 | // Responder is a back-channel for messages generated during | 29 | // Responder is a back-channel for messages generated during |
30 | // message processing. The Connection type is a responder | 30 | // message processing. The Connection type is a responder |
31 | // and used as such in ServeClient(). | 31 | // and used as such in ServeClient(). |
@@ -38,7 +38,7 @@ type Responder interface { | |||
38 | Receiver() *util.PeerID | 38 | Receiver() *util.PeerID |
39 | } | 39 | } |
40 | 40 | ||
41 | //---------------------------------------------------------------------- | 41 | // ---------------------------------------------------------------------- |
42 | // TransportResponder is used as a responder in message handling for | 42 | // TransportResponder is used as a responder in message handling for |
43 | // messages received from Transport. It is used by Endpoint instances | 43 | // messages received from Transport. It is used by Endpoint instances |
44 | // to define custom responders for messages received. | 44 | // to define custom responders for messages received. |
diff --git a/src/gnunet/util/misc.go b/src/gnunet/util/misc.go index 87a2149..c5fd308 100644 --- a/src/gnunet/util/misc.go +++ b/src/gnunet/util/misc.go | |||
@@ -108,7 +108,6 @@ func Shorten(s string, n int) string { | |||
108 | return s[:p+k] + "..." + s[l-p:] | 108 | return s[:p+k] + "..." + s[l-p:] |
109 | } | 109 | } |
110 | 110 | ||
111 | //---------------------------------------------------------------------- | ||
112 | // Dump instance | 111 | // Dump instance |
113 | func Dump(obj any, format string) string { | 112 | func Dump(obj any, format string) string { |
114 | switch format { | 113 | switch format { |