aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/server.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-02-20 00:08:18 +0800
committerFelix Lange <fjl@twurst.com>2015-02-20 00:08:18 +0800
commitdd871e791cdd2aefd001f6c3a11ac9378dde0bf5 (patch)
tree4b8dab28150bd89691ef1720153d06e2cc4e4fa9 /p2p/server.go
parent3dbd32093cd1060c339b3351fbb676b8c7cc31f0 (diff)
downloaddexon-dd871e791cdd2aefd001f6c3a11ac9378dde0bf5.tar
dexon-dd871e791cdd2aefd001f6c3a11ac9378dde0bf5.tar.gz
dexon-dd871e791cdd2aefd001f6c3a11ac9378dde0bf5.tar.bz2
dexon-dd871e791cdd2aefd001f6c3a11ac9378dde0bf5.tar.lz
dexon-dd871e791cdd2aefd001f6c3a11ac9378dde0bf5.tar.xz
dexon-dd871e791cdd2aefd001f6c3a11ac9378dde0bf5.tar.zst
dexon-dd871e791cdd2aefd001f6c3a11ac9378dde0bf5.zip
p2p: initialize Server.ourHandshake before accepting connections
Diffstat (limited to 'p2p/server.go')
-rw-r--r--p2p/server.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/p2p/server.go b/p2p/server.go
index 194dc3f1c..923716011 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -160,7 +160,7 @@ func (srv *Server) Start() (err error) {
}
srvlog.Infoln("Starting Server")
- // initialize all the fields
+ // static fields
if srv.PrivateKey == nil {
return fmt.Errorf("Server.PrivateKey must be set to a non-nil key")
}
@@ -170,31 +170,32 @@ func (srv *Server) Start() (err error) {
srv.quit = make(chan struct{})
srv.peers = make(map[discover.NodeID]*Peer)
srv.peerConnect = make(chan *discover.Node)
-
if srv.setupFunc == nil {
srv.setupFunc = setupConn
}
if srv.Blacklist == nil {
srv.Blacklist = NewBlacklist()
}
- if srv.ListenAddr != "" {
- if err := srv.startListening(); err != nil {
- return err
- }
- }
- // dial stuff
+ // node table
ntab, err := discover.ListenUDP(srv.PrivateKey, srv.ListenAddr, srv.NAT)
if err != nil {
return err
}
srv.ntab = ntab
+ // handshake
srv.ourHandshake = &protoHandshake{Version: baseProtocolVersion, Name: srv.Name, ID: ntab.Self()}
for _, p := range srv.Protocols {
srv.ourHandshake.Caps = append(srv.ourHandshake.Caps, p.cap())
}
+ // listen/dial
+ if srv.ListenAddr != "" {
+ if err := srv.startListening(); err != nil {
+ return err
+ }
+ }
if srv.Dialer == nil {
srv.Dialer = &net.Dialer{Timeout: defaultDialTimeout}
}