aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/wnode/main.go
diff options
context:
space:
mode:
authorVlad <gluk256@gmail.com>2018-03-01 23:04:09 +0800
committerVlad <gluk256@gmail.com>2018-03-01 23:04:09 +0800
commitee75a90ab41fd9a2e5676a2371e529ac2908befa (patch)
tree4545344b40b16757115b081b6bedd610ceb591e1 /cmd/wnode/main.go
parent5a150e1b7724c91009a237ab0879cd64844b390d (diff)
downloadgo-tangerine-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar
go-tangerine-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar.gz
go-tangerine-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar.bz2
go-tangerine-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar.lz
go-tangerine-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar.xz
go-tangerine-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar.zst
go-tangerine-ee75a90ab41fd9a2e5676a2371e529ac2908befa.zip
whisper: topics replaced by bloom filters
Diffstat (limited to 'cmd/wnode/main.go')
-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
+ }
+}