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