Skip to content

Commit 9c2ecfc

Browse files
committed
WIP- Fabric gossip component
This is a commit that contains only APIs and protobuff The API between the ledger and the gossip component is in gossip/api/api.go Change-Id: I9f6aef85f3b03e2d3a6b9850148e9cf4d1a93ce3 Signed-off-by: Yacov Manevich <[email protected]>
1 parent 55593ac commit 9c2ecfc

File tree

6 files changed

+1024
-0
lines changed

6 files changed

+1024
-0
lines changed

gossip/api/api.go

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package api
18+
19+
import (
20+
"github.com/hyperledger/fabric/gossip/discovery"
21+
"google.golang.org/grpc"
22+
)
23+
24+
type GossipEmitterFactory interface {
25+
NewGossipEmitter(id string, discSvc discovery.DiscoveryService) GossipService
26+
}
27+
28+
// GossipService is used to publish new blocks to the gossip network
29+
type GossipService interface {
30+
// payload: Holds the block's content, hash and seqNum
31+
Publish(payload Payload) error
32+
}
33+
34+
type BindAddress struct {
35+
Host string
36+
Port int16
37+
}
38+
39+
// Payload defines an object that contains a ledger block
40+
type Payload struct {
41+
Data []byte // The content of the message, possibly encrypted or signed
42+
Hash string // The message hash
43+
SeqNum uint64 // The message sequence number
44+
}
45+
46+
type GossipMemberFactory interface {
47+
NewGossipMember(discovery.DiscoveryService, ReplicationProvider, MessageCryptoService, MessagePolicyVerifier, *grpc.Server) GossipMember
48+
49+
NewGossipMemberWithRPCServer(discovery.DiscoveryService, ReplicationProvider, MessageCryptoService, MessagePolicyVerifier, BindAddress) (GossipMember, error)
50+
}
51+
52+
// GossipMember is used to obtain new blocks from the gossip network
53+
type GossipMember interface {
54+
// RegisterCallback registers a callback that is invoked on messages
55+
// from startSeq to endSeq and invokes the callback when they arrive
56+
RegisterCallback(startSeq uint64, endSeq uint64, callback func([]Payload))
57+
}
58+
59+
// ReplicationProvider used by the GossipMember in order to obtain Blocks of
60+
// certain seqNum range to be sent to the requester
61+
type ReplicationProvider interface {
62+
// GetData used by the gossip component to obtain certain blocks from the ledger.
63+
// Returns the blocks requested with the given sequence numbers, or an error if
64+
// some block requested is not available.
65+
GetData(startSeqNum uint64, endSeqNum uint64) ([]Payload, error)
66+
67+
// LastBlockSeq used by the gossip component to obtain the last sequence of a block the ledger has.
68+
LastBlockSeq() uint64
69+
}
70+
71+
// MessageCryptoVerifier verifies the message's authenticity,
72+
// if messages are cryptographically signed
73+
type MessageCryptoService interface {
74+
// Verify returns nil whether the message and its identifier are authentic,
75+
// otherwise returns an error
76+
Verify(seqNum uint64, sender string, payload Payload) error
77+
78+
// Sign signs the payload
79+
Sign(sender string, Payload Payload) Payload
80+
81+
// SignBlob signs a blob
82+
SignBlob([]byte) []byte
83+
84+
// VerifyBlob verifies a blob, returns error on failure
85+
// and nil if the blob is correctly signed
86+
VerifyBlob(sender string, blob []byte) error
87+
}
88+
89+
// MessagePolicyVerifier verifies whether the message conforms to all required policies,
90+
// and can be safely delivered to the user.
91+
type MessagePolicyVerifier interface {
92+
Verify(seqNum uint64, sender string, payload Payload) error
93+
}

gossip/comm/comm.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package comm
18+
19+
import (
20+
"github.com/hyperledger/fabric/gossip/proto"
21+
"sync"
22+
)
23+
24+
type CommModule interface {
25+
// Send sends a message to endpoints
26+
Send(msg *proto.GossipMessage, endpoints ...string)
27+
28+
// Probe probes a remote node and returns nil if its responsive
29+
Probe(endpoint string) error
30+
31+
// Accept returns a dedicated read-only channel for messages sent by other nodes that match a certain predicate.
32+
// Each message from the channel can be used to send a reply back to the sender
33+
Accept(MessageAcceptor) <-chan *ReceivedMessage
34+
35+
// PresumedDead returns a read-only channel for node endpoints that are suspected to be offline
36+
PresumedDead() <-chan string
37+
38+
// CloseConn closes a connection to a certain endpoint
39+
CloseConn(endpoint string)
40+
41+
// Stop stops the module
42+
Stop()
43+
}
44+
45+
46+
type MessageAcceptor func(*proto.GossipMessage) bool
47+
48+
type ReceivedMessage struct {
49+
*proto.GossipMessage
50+
lock *sync.Mutex
51+
srvStream proto.Gossip_GossipStreamServer
52+
clStream proto.Gossip_GossipStreamClient
53+
}

gossip/discovery/discovery.go

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package discovery
18+
19+
import "github.com/hyperledger/fabric/gossip/proto"
20+
21+
// CryptoService is an interface that the discovery expects to be implemented and passed on creation
22+
type CryptoService interface {
23+
// validateAliveMsg validates that an Alive message is authentic
24+
ValidateAliveMsg(*proto.AliveMessage) bool
25+
26+
// SignMessage signs an AliveMessage and updates its signature field
27+
SignMessage(*proto.AliveMessage) *proto.AliveMessage
28+
}
29+
30+
// CommService is an interface that the discovery expects to be implemented and passed on creation
31+
type CommService interface {
32+
// Gossip gossips a message
33+
Gossip(msg *proto.GossipMessage)
34+
35+
// SendToPeer sends to a given peer a message.
36+
// The nonce can be anything since the communication module handles the nonce itself
37+
SendToPeer(peer *NetworkMember, msg *proto.GossipMessage)
38+
39+
// Ping probes a remote peer and returns if it's responsive or not
40+
Ping(peer *NetworkMember) bool
41+
42+
// Accept returns a read-only channel for membership messages sent from remote peers
43+
Accept() <-chan GossipMsg
44+
45+
// PresumedDead returns a read-only channel for peers that are presumed to be dead
46+
PresumedDead() <-chan string
47+
48+
// CloseConn orders to close the connection with a certain peer
49+
CloseConn(id string)
50+
}
51+
52+
type GossipMsg interface {
53+
GetGossipMessage() *proto.GossipMessage
54+
}
55+
56+
type NetworkMember struct {
57+
Id string
58+
Endpoint string
59+
Metadata []byte
60+
}
61+
62+
type DiscoveryService interface {
63+
64+
// Self returns this instance's membership information
65+
Self() NetworkMember
66+
67+
// UpdateMetadata updates this instance's metadata
68+
UpdateMetadata([]byte)
69+
70+
// UpdateEndpoint updates this instance's endpoint
71+
UpdateEndpoint(string)
72+
73+
// Stops this instance
74+
Stop()
75+
76+
// GetMembership returns the alive members in the view
77+
GetMembership() []NetworkMember
78+
}

gossip/gossip/gossip.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package gossip
18+
19+
import (
20+
"github.com/hyperledger/fabric/gossip/discovery"
21+
"github.com/hyperledger/fabric/gossip/proto"
22+
"time"
23+
)
24+
25+
type GossipService interface {
26+
27+
// GetPeersMetadata returns a mapping of endpoint --> metadata
28+
GetPeersMetadata() map[string][]byte
29+
30+
// UpdateMetadata updates the self metadata of the discovery layer
31+
UpdateMetadata([]byte)
32+
33+
// Gossip sends a message to other peers to the network
34+
Gossip(msg *proto.GossipMessage)
35+
36+
// Accept returns a channel that outputs messages from other peers
37+
Accept(MessageAcceptor) <-chan *proto.GossipMessage
38+
39+
// Stop stops the gossip component
40+
Stop()
41+
}
42+
43+
type MessageAcceptor func(*proto.GossipMessage) bool
44+
45+
type GossipConfig struct {
46+
BindPort int
47+
Id string
48+
SelfEndpoint string
49+
BootstrapPeers []*discovery.NetworkMember
50+
PropagateIterations int
51+
PropagatePeerNum int
52+
53+
MaxMessageCountToStore int
54+
55+
MaxPropagationBurstSize int
56+
MaxPropagationBurstLatency time.Duration
57+
58+
PullInterval time.Duration
59+
PullPeerNum int
60+
}

0 commit comments

Comments
 (0)