Skip to content

Commit

Permalink
Ensure noise.Listener does not return error on crypto error.
Browse files Browse the repository at this point in the history
  • Loading branch information
林志宇 committed May 31, 2019
1 parent 141df25 commit c8bf29e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 18 additions & 16 deletions internal/noise/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,25 @@ func WrapListener(lis net.Listener, pk cipher.PubKey, sk cipher.SecKey, init boo
// Accept calls Accept from the underlying net.Listener and encrypts the
// obtained net.Conn with noise.
func (ml *Listener) Accept() (net.Conn, error) {
conn, err := ml.Listener.Accept()
if err != nil {
return nil, err
}
ns, err := New(ml.pattern, Config{
LocalPK: ml.pk,
LocalSK: ml.sk,
Initiator: ml.init,
})
if err != nil {
return nil, err
}
rw := NewReadWriter(conn, ns)
if err := rw.Handshake(time.Second * 10); err != nil {
return nil, err
for {
conn, err := ml.Listener.Accept()
if err != nil {
return nil, err
}
ns, err := New(ml.pattern, Config{
LocalPK: ml.pk,
LocalSK: ml.sk,
Initiator: ml.init,
})
if err != nil {
continue
}
rw := NewReadWriter(conn, ns)
if err := rw.Handshake(time.Second * 10); err != nil {
continue
}
return &Conn{Conn: conn, ns: rw}, nil
}
return &Conn{Conn: conn, ns: rw}, nil
}

// Addr returns the local address of the noise-encrypted Listener.
Expand Down
2 changes: 1 addition & 1 deletion pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (node *Node) SpawnApp(config *AppConfig, startCh chan<- struct{}) error {

bind := &appBind{conn, -1}
if app, ok := reservedPorts[config.Port]; ok && app != config.App {
return fmt.Errorf("can't bind to reserved port %d", config.Port)
return fmt.Errorf("can't bind to reserved port %d (which is reserved for %s)", config.Port, app)
}

node.startedMu.Lock()
Expand Down

0 comments on commit c8bf29e

Please sign in to comment.