Skip to content

Commit

Permalink
Refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Jul 4, 2019
1 parent dfd27c2 commit b51c007
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions pkg/setup/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,41 +146,31 @@ func CreateLoop(p *Protocol, l *routing.Loop) error {
if err := p.WritePacket(PacketCreateLoop, l); err != nil {
return err
}
if err := readAndDecodePacket(p, nil); err != nil { // TODO: data race.
return err
}
return nil
return readAndDecodePacket(p, nil) // TODO: data race.
}

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

// CloseLoop sends CloseLoop setup request.
func CloseLoop(p *Protocol, l *LoopData) error {
if err := p.WritePacket(PacketCloseLoop, l); err != nil {
return err
}
if err := readAndDecodePacket(p, nil); err != nil {
return err
}
return nil
return readAndDecodePacket(p, nil)
}

// LoopClosed sends LoopClosed setup request.
func LoopClosed(p *Protocol, l *LoopData) error {
if err := p.WritePacket(PacketLoopClosed, l); err != nil {
return err
}
if err := readAndDecodePacket(p, nil); err != nil {
return err
}
return nil
return readAndDecodePacket(p, nil)
}

func readAndDecodePacket(p *Protocol, v interface{}) error {
Expand All @@ -194,8 +184,5 @@ func readAndDecodePacket(p *Protocol, v interface{}) error {
if v == nil {
return nil
}
if err = json.Unmarshal(raw, v); err != nil {
return err
}
return nil
return json.Unmarshal(raw, v)
}

0 comments on commit b51c007

Please sign in to comment.