add -crypto option to switch encryption on by a flag

This commit is contained in:
zelig 2015-01-23 13:00:02 +00:00
parent 2f00e5cad1
commit 7f12ac702f
6 changed files with 21 additions and 10 deletions

View file

@ -65,6 +65,7 @@ var (
SHH bool
Dial bool
PrintVersion bool
Encryption bool
)
// flags specific to cli client
@ -115,6 +116,7 @@ func Init() {
flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")
flag.StringVar(&ImportChain, "chain", "", "Imports given chain")
flag.BoolVar(&Encryption, "crypto", false, "whether to use encryption (experimental, temporary)")
flag.BoolVar(&Dump, "dump", false, "output the ethereum state in JSON format. Sub args [number, hash]")
flag.StringVar(&DumpHash, "hash", "", "specify arg in hex")
flag.IntVar(&DumpNumber, "number", -1, "specify arg in number")

View file

@ -75,6 +75,7 @@ func main() {
KeyRing: KeyRing,
Shh: SHH,
Dial: Dial,
Encryption: Encryption,
})
if err != nil {

View file

@ -36,8 +36,9 @@ type Config struct {
NATType string
PMPGateway string
Shh bool
Dial bool
Shh bool
Dial bool
Encryption bool
KeyManager *crypto.KeyManager
}
@ -107,7 +108,7 @@ func New(config *Config) (*Ethereum, error) {
keyManager.Init(config.KeyRing, 0, false)
// Create a new client id for this instance. This will help identifying the node on the network
clientId := p2p.NewSimpleClientIdentity(config.Name, config.Version, config.Identifier, keyManager.PublicKey())
clientId := p2p.NewSimpleClientIdentity(config.Name, config.Version, config.Identifier, keyManager.PrivateKey(), keyManager.PublicKey())
saveProtocolVersion(db)
//ethutil.Config.Db = db
@ -143,12 +144,13 @@ func New(config *Config) (*Ethereum, error) {
fmt.Println(nat)
eth.net = &p2p.Server{
Identity: clientId,
MaxPeers: config.MaxPeers,
Protocols: protocols,
Blacklist: eth.blacklist,
NAT: p2p.UPNP(),
NoDial: !config.Dial,
Identity: clientId,
MaxPeers: config.MaxPeers,
Protocols: protocols,
Blacklist: eth.blacklist,
NAT: p2p.UPNP(),
NoDial: !config.Dial,
Encryption: config.Encryption,
}
if len(config.Port) > 0 {

View file

@ -97,7 +97,7 @@ func runEthProtocol(txPool txPool, chainManager chainManager, blockPool blockPoo
blockPool: blockPool,
rw: rw,
peer: peer,
id: fmt.Sprintf("%x", peer.Identity().Pubkey()[:8]),
id: fmt.Sprintf("%x", peer.PublicKey()[:8]),
}
err = self.handleStatus()
if err == nil {

View file

@ -107,6 +107,9 @@ func newServerPeer(server *Server, conn net.Conn, dialAddr *peerAddr) *Peer {
p.otherPeers = server.Peers
p.pubkeyHook = server.verifyPeer
p.runBaseProtocol = true
if server.Encryption {
p.CryptoType = EthCrypto
}
// laddr can be updated concurrently by NAT traversal.
// newServerPeer must be called with the server lock held.

View file

@ -62,6 +62,9 @@ type Server struct {
// If NoDial is true, the server will not dial any peers.
NoDial bool
// whether or not use encryption
Encryption bool
// Hook for testing. This is useful because we can inhibit
// the whole protocol stack.
newPeerFunc peerFunc