aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorGuillaume Ballet <gballet@gmail.com>2018-03-02 03:27:20 +0800
committerGitHub <noreply@github.com>2018-03-02 03:27:20 +0800
commita76e46e3d7cb77bfcbc95d92df9f4b6ccdd742f2 (patch)
treeaa033434cf54c7194363a8a0bc64cac66682db2a /cmd
parent3ca3fffdf01b94244ef6c2d93ed38a30da9fcb0a (diff)
parentee75a90ab41fd9a2e5676a2371e529ac2908befa (diff)
downloadgo-tangerine-a76e46e3d7cb77bfcbc95d92df9f4b6ccdd742f2.tar
go-tangerine-a76e46e3d7cb77bfcbc95d92df9f4b6ccdd742f2.tar.gz
go-tangerine-a76e46e3d7cb77bfcbc95d92df9f4b6ccdd742f2.tar.bz2
go-tangerine-a76e46e3d7cb77bfcbc95d92df9f4b6ccdd742f2.tar.lz
go-tangerine-a76e46e3d7cb77bfcbc95d92df9f4b6ccdd742f2.tar.xz
go-tangerine-a76e46e3d7cb77bfcbc95d92df9f4b6ccdd742f2.tar.zst
go-tangerine-a76e46e3d7cb77bfcbc95d92df9f4b6ccdd742f2.zip
Merge pull request #16223 from gluk256/300-msg-serialiation
whisper: topics replaced by bloom filters in mailserver communication
Diffstat (limited to 'cmd')
-rw-r--r--cmd/wnode/main.go40
1 files changed, 33 insertions, 7 deletions
diff --git a/cmd/wnode/main.go b/cmd/wnode/main.go
index f8606bf82..ccfdd4626 100644
--- a/cmd/wnode/main.go
+++ b/cmd/wnode/main.go
@@ -22,6 +22,7 @@ package main
import (
"bufio"
"crypto/ecdsa"
+ crand "crypto/rand"
"crypto/sha512"
"encoding/binary"
"encoding/hex"
@@ -48,6 +49,7 @@ import (
)
const quitCommand = "~Q"
+const entropySize = 32
// singletons
var (
@@ -55,6 +57,7 @@ var (
shh *whisper.Whisper
done chan struct{}
mailServer mailserver.WMailServer
+ entropy [entropySize]byte
input = bufio.NewReader(os.Stdin)
)
@@ -274,6 +277,11 @@ func initialize() {
TrustedNodes: peers,
},
}
+
+ _, err = crand.Read(entropy[:])
+ if err != nil {
+ utils.Fatalf("crypto/rand failed: %s", err)
+ }
}
func startServer() {
@@ -614,10 +622,10 @@ func writeMessageToFile(dir string, msg *whisper.ReceivedMessage) {
}
func requestExpiredMessagesLoop() {
- var key, peerID []byte
+ var key, peerID, bloom []byte
var timeLow, timeUpp uint32
var t string
- var xt, empty whisper.TopicType
+ var xt whisper.TopicType
keyID, err := shh.AddSymKeyFromPassword(msPassword)
if err != nil {
@@ -640,18 +648,19 @@ func requestExpiredMessagesLoop() {
utils.Fatalf("Failed to parse the topic: %s", err)
}
xt = whisper.BytesToTopic(x)
+ bloom = whisper.TopicToBloom(xt)
+ obfuscateBloom(bloom)
+ } else {
+ bloom = whisper.MakeFullNodeBloom()
}
if timeUpp == 0 {
timeUpp = 0xFFFFFFFF
}
- data := make([]byte, 8+whisper.TopicLength)
+ data := make([]byte, 8, 8+whisper.BloomFilterSize)
binary.BigEndian.PutUint32(data, timeLow)
binary.BigEndian.PutUint32(data[4:], timeUpp)
- copy(data[8:], xt[:])
- if xt == empty {
- data = data[:8]
- }
+ data = append(data, bloom...)
var params whisper.MessageParams
params.PoW = *argServerPoW
@@ -685,3 +694,20 @@ func extractIDFromEnode(s string) []byte {
}
return n.ID[:]
}
+
+// obfuscateBloom adds 16 random bits to the the bloom
+// filter, in order to obfuscate the containing topics.
+// it does so deterministically within every session.
+// despite additional bits, it will match on average
+// 32000 times less messages than full node's bloom filter.
+func obfuscateBloom(bloom []byte) {
+ const half = entropySize / 2
+ for i := 0; i < half; i++ {
+ x := int(entropy[i])
+ if entropy[half+i] < 128 {
+ x += 256
+ }
+
+ bloom[x/8] = 1 << uint(x%8) // set the bit number X
+ }
+}