Skip to content

Commit

Permalink
Add portable analogs of some common channel call errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gotoxu committed Apr 10, 2019
1 parent 5278562 commit e3bad77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions gossip/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ package gossip
import (
"crypto/x509"

"github.com/pkg/errors"
"github.com/rkcloudchain/rksync/channel"
"github.com/rkcloudchain/rksync/common"
"github.com/rkcloudchain/rksync/filter"
"github.com/rkcloudchain/rksync/protos"
)

// Portable analogs of some common channel call errors
var (
ErrChannelExist = errors.New("channel already exists")
ErrChannelNotExist = errors.New("channel does not exist")
)

type channelRoutingFilterFactory func(channel.Channel) filter.RoutingFilter

// Gossip is the interface of the gossip component
Expand Down
4 changes: 2 additions & 2 deletions gossip/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (g *gossipService) CreateChain(chainMac common.ChainMac, chainID string, fi
}

if c := g.chanState.getChannelByMAC(chainMac); c != nil {
return nil, errors.Errorf("Channel (%s) already exists", chainID)
return nil, ErrChannelExist
}

gc := g.chanState.joinChannel(chainMac, chainID, true)
Expand All @@ -261,7 +261,7 @@ func (g *gossipService) CloseChain(chainMac common.ChainMac, notify bool) error

gc := g.chanState.getChannelByMAC(chainMac)
if gc == nil {
return errors.Errorf("Failed to find channel with mac: %s", chainMac)
return ErrChannelNotExist
}
chainState := gc.Self()
msg, err := chainState.Envelope.ToRKSyncMessage()
Expand Down

0 comments on commit e3bad77

Please sign in to comment.