提交 f0019754 作者: Brian Tiger Chow

Merge pull request #104 from jbenet/feat/fix-ping

Fixed Ping (minor)
...@@ -67,8 +67,12 @@ func (s *SecurePipe) handshake() error { ...@@ -67,8 +67,12 @@ func (s *SecurePipe) handshake() error {
return err return err
} }
// u.POut("sending encoded handshake\n") // Send our Propose packet
s.insecure.Out <- encoded select {
case s.insecure.Out <- encoded:
case <-s.ctx.Done():
return ErrClosed
}
// Parse their Propose packet and generate an Exchange packet. // Parse their Propose packet and generate an Exchange packet.
// Exchange = (EphemeralPubKey, Signature) // Exchange = (EphemeralPubKey, Signature)
...@@ -137,7 +141,12 @@ func (s *SecurePipe) handshake() error { ...@@ -137,7 +141,12 @@ func (s *SecurePipe) handshake() error {
exEncoded, err := proto.Marshal(exPacket) exEncoded, err := proto.Marshal(exPacket)
s.insecure.Out <- exEncoded // send out Exchange packet
select {
case s.insecure.Out <- exEncoded:
case <-s.ctx.Done():
return ErrClosed
}
// Parse their Exchange packet and generate a Finish packet. // Parse their Exchange packet and generate a Finish packet.
// Finish = E('Finish') // Finish = E('Finish')
...@@ -182,7 +191,14 @@ func (s *SecurePipe) handshake() error { ...@@ -182,7 +191,14 @@ func (s *SecurePipe) handshake() error {
finished := []byte("Finished") finished := []byte("Finished")
s.Out <- finished // send finished msg
select {
case <-s.ctx.Done():
return ErrClosed
case s.Out <- finished:
}
// recv finished msg
var resp2 []byte var resp2 []byte
select { select {
case <-s.ctx.Done(): case <-s.ctx.Done():
...@@ -194,7 +210,7 @@ func (s *SecurePipe) handshake() error { ...@@ -194,7 +210,7 @@ func (s *SecurePipe) handshake() error {
return errors.New("Negotiation failed.") return errors.New("Negotiation failed.")
} }
u.DOut("[%s] identify: Got node id: %s\n", s.local.ID.Pretty(), s.remote.ID.Pretty()) u.DOut("[%s] handshake: Got node id: %s\n", s.local.ID.Pretty(), s.remote.ID.Pretty())
return nil return nil
} }
......
...@@ -104,8 +104,7 @@ func (dht *IpfsDHT) handlePutValue(p *peer.Peer, pmes *Message) (*Message, error ...@@ -104,8 +104,7 @@ func (dht *IpfsDHT) handlePutValue(p *peer.Peer, pmes *Message) (*Message, error
func (dht *IpfsDHT) handlePing(p *peer.Peer, pmes *Message) (*Message, error) { func (dht *IpfsDHT) handlePing(p *peer.Peer, pmes *Message) (*Message, error) {
u.DOut("[%s] Responding to ping from [%s]!\n", dht.self.ID.Pretty(), p.ID.Pretty()) u.DOut("[%s] Responding to ping from [%s]!\n", dht.self.ID.Pretty(), p.ID.Pretty())
return pmes, nil
return newMessage(pmes.GetType(), "", int(pmes.GetClusterLevel())), nil
} }
func (dht *IpfsDHT) handleFindPeer(p *peer.Peer, pmes *Message) (*Message, error) { func (dht *IpfsDHT) handleFindPeer(p *peer.Peer, pmes *Message) (*Message, error) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论