Skip to content

Commit

Permalink
Remove noise res from connectLoop, ConfirmLoop signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Jul 3, 2019
1 parent 92df154 commit 6cf72c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
16 changes: 7 additions & 9 deletions pkg/setup/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ func (sn *Node) createLoop(l *routing.Loop) error {
responder := l.Responder()

ldR := &LoopData{RemotePK: initiator, RemotePort: l.LocalPort, LocalPort: l.RemotePort, RouteID: rRouteID}
if _, err := sn.connectLoop(responder, ldR); err != nil {
if err := sn.connectLoop(responder, ldR); err != nil {
sn.Logger.Warnf("Failed to confirm loop with responder: %s", err)
return fmt.Errorf("loop connect: %s", err)
}

ldI := &LoopData{RemotePK: responder, RemotePort: l.RemotePort, LocalPort: l.LocalPort, RouteID: fRouteID}
if _, err := sn.connectLoop(initiator, ldI); err != nil {
if err := sn.connectLoop(initiator, ldI); err != nil {
sn.Logger.Warnf("Failed to confirm loop with initiator: %s", err)
if err := sn.closeLoop(responder, ldR); err != nil {
sn.Logger.Warnf("Failed to close loop: %s", err)
Expand Down Expand Up @@ -221,22 +221,20 @@ func (sn *Node) serveTransport(tr transport.Transport) error {
return proto.WritePacket(RespSuccess, nil)
}

func (sn *Node) connectLoop(on cipher.PubKey, ld *LoopData) (res []byte, err error) {
func (sn *Node) connectLoop(on cipher.PubKey, ld *LoopData) error {
tr, err := sn.tm.CreateTransport(context.Background(), on, dmsg.Type, false)
if err != nil {
err = fmt.Errorf("transport: %s", err)
return
return fmt.Errorf("transport: %s", err)
}
defer tr.Close()

proto := NewSetupProtocol(tr)
res, err = ConfirmLoop(proto, ld)
if err != nil {
return nil, err
if err := ConfirmLoop(proto, ld); err != nil {
return err
}

sn.Logger.Infof("Confirmed loop on %s with %s. RemotePort: %d. LocalPort: %d", on, ld.RemotePK, ld.RemotePort, ld.LocalPort)
return res, nil
return nil
}

func (sn *Node) closeLoop(on cipher.PubKey, ld *LoopData) error {
Expand Down
11 changes: 4 additions & 7 deletions pkg/setup/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,12 @@ func CreateLoop(p *Protocol, l *routing.Loop) error {
}

// ConfirmLoop sends ConfirmLoop setup request.
func ConfirmLoop(p *Protocol, l *LoopData) (noiseRes []byte, err error) {
if err = p.WritePacket(PacketConfirmLoop, l); err != nil {
return
func ConfirmLoop(p *Protocol, l *LoopData) error {
if err := p.WritePacket(PacketConfirmLoop, l); err != nil {
return err
}
var res []byte
if err = readAndDecodePacket(p, &res); err != nil {
return
}
return res, nil
return readAndDecodePacket(p, &res)
}

// CloseLoop sends CloseLoop setup request.
Expand Down

0 comments on commit 6cf72c5

Please sign in to comment.