mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
whisper: split cmd and mailserver
This commit is contained in:
parent
b702561e87
commit
7a86fe54f2
2 changed files with 23 additions and 23 deletions
|
|
@ -43,16 +43,14 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||||
|
"github.com/ethereum/go-ethereum/whisper/mailserver"
|
||||||
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
|
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
|
||||||
"golang.org/x/crypto/pbkdf2"
|
"golang.org/x/crypto/pbkdf2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const sizeOfInt = 4
|
const (
|
||||||
|
quitCommand = "~Q"
|
||||||
var (
|
enodePrefix = "enode://"
|
||||||
quitCommand = "~Q"
|
|
||||||
enodePrefix = "enode://"
|
|
||||||
mailServerKeyName = "958e04ab302fb36ad2616a352cbac79dfa08f43d325d0833e07061a9ef8c383d"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// singletons
|
// singletons
|
||||||
|
|
@ -61,7 +59,7 @@ var (
|
||||||
shh *whisper.Whisper
|
shh *whisper.Whisper
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
input *bufio.Reader = bufio.NewReader(os.Stdin)
|
input *bufio.Reader = bufio.NewReader(os.Stdin)
|
||||||
mailServer WMailServer
|
mailServer mailserver.WMailServer
|
||||||
)
|
)
|
||||||
|
|
||||||
// encryption
|
// encryption
|
||||||
|
|
@ -477,11 +475,11 @@ func requestExpiredMessagesLoop() {
|
||||||
var t string
|
var t string
|
||||||
var xt, empty whisper.TopicType
|
var xt, empty whisper.TopicType
|
||||||
|
|
||||||
err := shh.AddSymKey(mailServerKeyName, []byte(msPassword))
|
err := shh.AddSymKey(mailserver.MailServerKeyName, []byte(msPassword))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("Failed to create symmetric key for mail request: %s", err)
|
utils.Fatalf("Failed to create symmetric key for mail request: %s", err)
|
||||||
}
|
}
|
||||||
key = shh.GetSymKey(mailServerKeyName)
|
key = shh.GetSymKey(mailserver.MailServerKeyName)
|
||||||
peerID = extractIdFromEnode(*argEnode)
|
peerID = extractIdFromEnode(*argEnode)
|
||||||
shh.MarkPeerTrusted(peerID)
|
shh.MarkPeerTrusted(peerID)
|
||||||
|
|
||||||
|
|
@ -500,12 +498,12 @@ func requestExpiredMessagesLoop() {
|
||||||
timeUpp = 0xFFFFFFFF
|
timeUpp = 0xFFFFFFFF
|
||||||
}
|
}
|
||||||
|
|
||||||
data := make([]byte, sizeOfInt*2+whisper.TopicLength)
|
data := make([]byte, 8+whisper.TopicLength)
|
||||||
binary.BigEndian.PutUint32(data, timeLow)
|
binary.BigEndian.PutUint32(data, timeLow)
|
||||||
binary.BigEndian.PutUint32(data[sizeOfInt:], timeUpp)
|
binary.BigEndian.PutUint32(data[4:], timeUpp)
|
||||||
copy(data[sizeOfInt*2:], xt[:])
|
copy(data[8:], xt[:])
|
||||||
if xt == empty {
|
if xt == empty {
|
||||||
data = data[:sizeOfInt*2]
|
data = data[:8]
|
||||||
}
|
}
|
||||||
|
|
||||||
var params whisper.MessageParams
|
var params whisper.MessageParams
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package main
|
package mailserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
@ -30,6 +30,8 @@ import (
|
||||||
"github.com/syndtr/goleveldb/leveldb/util"
|
"github.com/syndtr/goleveldb/leveldb/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const MailServerKeyName = "958e04ab302fb36ad2616a352cbac79d"
|
||||||
|
|
||||||
type WMailServer struct {
|
type WMailServer struct {
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
w *whisper.Whisper
|
w *whisper.Whisper
|
||||||
|
|
@ -44,13 +46,13 @@ type DBKey struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDbKey(t uint32, h common.Hash) *DBKey {
|
func NewDbKey(t uint32, h common.Hash) *DBKey {
|
||||||
const sz = common.HashLength + sizeOfInt
|
const sz = common.HashLength + 4
|
||||||
var k DBKey
|
var k DBKey
|
||||||
k.timestamp = t
|
k.timestamp = t
|
||||||
k.hash = h
|
k.hash = h
|
||||||
k.raw = make([]byte, sz)
|
k.raw = make([]byte, sz)
|
||||||
binary.BigEndian.PutUint32(k.raw, k.timestamp)
|
binary.BigEndian.PutUint32(k.raw, k.timestamp)
|
||||||
copy(k.raw[sizeOfInt:], k.hash[:])
|
copy(k.raw[4:], k.hash[:])
|
||||||
return &k
|
return &k
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,11 +74,11 @@ func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, p
|
||||||
s.w = shh
|
s.w = shh
|
||||||
s.pow = pow
|
s.pow = pow
|
||||||
|
|
||||||
err = s.w.AddSymKey(mailServerKeyName, []byte(password))
|
err = s.w.AddSymKey(MailServerKeyName, []byte(password))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("Failed to create symmetric key for MailServer: %s", err)
|
utils.Fatalf("Failed to create symmetric key for MailServer: %s", err)
|
||||||
}
|
}
|
||||||
s.key = s.w.GetSymKey(mailServerKeyName)
|
s.key = s.w.GetSymKey(MailServerKeyName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WMailServer) Close() {
|
func (s *WMailServer) Close() {
|
||||||
|
|
@ -147,7 +149,7 @@ func (s *WMailServer) validate(peer *whisper.Peer, request *whisper.Envelope) (b
|
||||||
return false, 0, 0, topic
|
return false, 0, 0, topic
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(decrypted.Payload) < sizeOfInt*2 {
|
if len(decrypted.Payload) < 8 {
|
||||||
glog.V(logger.Warn).Infof("Undersized p2p request")
|
glog.V(logger.Warn).Infof("Undersized p2p request")
|
||||||
return false, 0, 0, topic
|
return false, 0, 0, topic
|
||||||
}
|
}
|
||||||
|
|
@ -157,11 +159,11 @@ func (s *WMailServer) validate(peer *whisper.Peer, request *whisper.Envelope) (b
|
||||||
return false, 0, 0, topic
|
return false, 0, 0, topic
|
||||||
}
|
}
|
||||||
|
|
||||||
lower := binary.BigEndian.Uint32(decrypted.Payload[:sizeOfInt])
|
lower := binary.BigEndian.Uint32(decrypted.Payload[:4])
|
||||||
upper := binary.BigEndian.Uint32(decrypted.Payload[sizeOfInt : sizeOfInt*2])
|
upper := binary.BigEndian.Uint32(decrypted.Payload[4:8])
|
||||||
|
|
||||||
if len(decrypted.Payload) == sizeOfInt*2+whisper.TopicLength {
|
if len(decrypted.Payload) >= 8+whisper.TopicLength {
|
||||||
topic = whisper.BytesToTopic(decrypted.Payload[sizeOfInt*2 : sizeOfInt*2+whisper.TopicLength])
|
topic = whisper.BytesToTopic(decrypted.Payload[8:])
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, lower, upper, topic
|
return true, lower, upper, topic
|
||||||
Loading…
Reference in a new issue