Skip to content

Commit

Permalink
Merge pull request #6 from rkcloudchain/master
Browse files Browse the repository at this point in the history
Release 1.0.1-rc1
  • Loading branch information
gotoxu authored Apr 28, 2019
2 parents 46a69e2 + 51f6747 commit 6fdc316
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions channel/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func (gc *gossipChannel) Initialize(chainID string, members []common.PKIidType,
}

func (gc *gossipChannel) AddMember(member common.PKIidType) (*protos.ChainState, error) {
// can't add self to the members
if bytes.Equal(member, gc.pkiID) {
return nil, errors.New("Can't add leader to the channel members")
}

gc.Lock()
defer gc.Unlock()

Expand All @@ -182,7 +187,7 @@ func (gc *gossipChannel) AddMember(member common.PKIidType) (*protos.ChainState,
return nil, err
}

for _, m := range stateInfo.Properties.Members {
for _, m := range gc.members {
if bytes.Equal(member, common.PKIidType(m)) {
return gc.chainStateMsg, nil
}
Expand Down Expand Up @@ -631,7 +636,10 @@ func (gc *gossipChannel) requestStateInfo() {
return
}

endpoints := filter.SelectPeers(gc.GetChannelConfig().PullPeerNum, gc.GetMembership(), gc.IsMemberInChan)
filters := filter.CombineRoutingFilters(gc.IsMemberInChan, func(member common.NetworkMember) bool {
return gc.pkiID.IsNotSameFilter(member.PKIID)
})
endpoints := filter.SelectPeers(gc.GetChannelConfig().PullPeerNum, gc.GetMembership(), filters)
gc.Send(req, endpoints...)
}

Expand Down
14 changes: 14 additions & 0 deletions gossip/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ import (
"google.golang.org/grpc"
)

func TestAddSelfToChainMembers(t *testing.T) {
gossipSvc1, err := CreateGossipServer([]string{"localhost:12053"}, "localhost:12053", 0)
require.NoError(t, err)
defer gossipSvc1.Stop()

mac := channel.GenerateMAC(gossipSvc1.SelfPKIid(), "testchannel")
_, err = gossipSvc1.CreateChain(mac, "testchannel", []*common.FileSyncInfo{})
assert.NoError(t, err)

_, err = gossipSvc1.AddMemberToChain(mac, gossipSvc1.SelfPKIid())
assert.Error(t, err)
assert.Contains(t, err.Error(), "Can't add leader to the channel members")
}

func TestChannelInit(t *testing.T) {
gossipSvc1, err := CreateGossipServer([]string{"localhost:9053"}, "localhost:9053", 0)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions gossip/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ func (g *gossipService) handleMessage(m protos.ReceivedMessage) {
}

if gc != nil {
gc.InitializeWithChainState(chainState)
gc.HandleMessage(m)
}
}
Expand Down

0 comments on commit 6fdc316

Please sign in to comment.