@@ -18,10 +18,11 @@ package broadcast
18
18
19
19
import (
20
20
"github.com/hyperledger/fabric/orderer/common/broadcastfilter"
21
- "github.com/hyperledger/fabric/orderer/common/configtx "
21
+ "github.com/hyperledger/fabric/orderer/multichain "
22
22
cb "github.com/hyperledger/fabric/protos/common"
23
23
ab "github.com/hyperledger/fabric/protos/orderer"
24
24
25
+ "github.com/golang/protobuf/proto"
25
26
"github.com/op/go-logging"
26
27
)
27
28
@@ -31,34 +32,24 @@ func init() {
31
32
logging .SetLevel (logging .DEBUG , "" )
32
33
}
33
34
34
- // Target defines an interface which the broadcast handler will direct broadcasts to
35
- type Target interface {
36
- // Enqueue accepts a message and returns true on acceptance, or false on shutdown
37
- Enqueue (env * cb.Envelope ) bool
38
- }
39
-
40
35
// Handler defines an interface which handles broadcasts
41
36
type Handler interface {
42
37
// Handle starts a service thread for a given gRPC connection and services the broadcast connection
43
38
Handle (srv ab.AtomicBroadcast_BroadcastServer ) error
44
39
}
45
40
46
41
type handlerImpl struct {
47
- queueSize int
48
- target Target
49
- filters * broadcastfilter.RuleSet
50
- configManager configtx.Manager
51
- exitChan chan struct {}
42
+ queueSize int
43
+ ml multichain.Manager
44
+ exitChan chan struct {}
52
45
}
53
46
54
47
// NewHandlerImpl constructs a new implementation of the Handler interface
55
- func NewHandlerImpl (queueSize int , target Target , filters * broadcastfilter. RuleSet , configManager configtx .Manager ) Handler {
48
+ func NewHandlerImpl (queueSize int , ml multichain .Manager ) Handler {
56
49
return & handlerImpl {
57
- queueSize : queueSize ,
58
- filters : filters ,
59
- configManager : configManager ,
60
- target : target ,
61
- exitChan : make (chan struct {}),
50
+ queueSize : queueSize ,
51
+ ml : ml ,
52
+ exitChan : make (chan struct {}),
62
53
}
63
54
}
64
55
@@ -70,25 +61,30 @@ func (bh *handlerImpl) Handle(srv ab.AtomicBroadcast_BroadcastServer) error {
70
61
return b .queueEnvelopes (srv )
71
62
}
72
63
64
+ type msgAndChainSupport struct {
65
+ msg * cb.Envelope
66
+ chainSupport multichain.ChainSupport
67
+ }
68
+
73
69
type broadcaster struct {
74
70
bs * handlerImpl
75
- queue chan * cb. Envelope
71
+ queue chan * msgAndChainSupport
76
72
}
77
73
78
74
func newBroadcaster (bs * handlerImpl ) * broadcaster {
79
75
b := & broadcaster {
80
76
bs : bs ,
81
- queue : make (chan * cb. Envelope , bs .queueSize ),
77
+ queue : make (chan * msgAndChainSupport , bs .queueSize ),
82
78
}
83
79
return b
84
80
}
85
81
86
82
func (b * broadcaster ) drainQueue () {
87
83
for {
88
84
select {
89
- case msg , ok := <- b .queue :
85
+ case msgAndChainSupport , ok := <- b .queue :
90
86
if ok {
91
- if ! b . bs . target .Enqueue (msg ) {
87
+ if ! msgAndChainSupport . chainSupport . Chain () .Enqueue (msgAndChainSupport . msg ) {
92
88
return
93
89
}
94
90
} else {
@@ -108,14 +104,27 @@ func (b *broadcaster) queueEnvelopes(srv ab.AtomicBroadcast_BroadcastServer) err
108
104
return err
109
105
}
110
106
111
- action , _ := b .bs .filters .Apply (msg )
107
+ payload := & cb.Payload {}
108
+ err = proto .Unmarshal (msg .Payload , payload )
109
+ if payload .Header == nil || payload .Header .ChainHeader == nil || payload .Header .ChainHeader .ChainID == nil {
110
+ logger .Debugf ("Received malformed message, dropping connection" )
111
+ return srv .Send (& ab.BroadcastResponse {Status : cb .Status_BAD_REQUEST })
112
+ }
113
+
114
+ chainSupport , ok := b .bs .ml .GetChain (payload .Header .ChainHeader .ChainID )
115
+ if ! ok {
116
+ // XXX Hook in chain creation logic here
117
+ panic ("Unimplemented" )
118
+ }
119
+
120
+ action , _ := chainSupport .Filters ().Apply (msg )
112
121
113
122
switch action {
114
123
case broadcastfilter .Reconfigure :
115
124
fallthrough
116
125
case broadcastfilter .Accept :
117
126
select {
118
- case b .queue <- msg :
127
+ case b .queue <- & msgAndChainSupport { msg : msg , chainSupport : chainSupport } :
119
128
err = srv .Send (& ab.BroadcastResponse {Status : cb .Status_SUCCESS })
120
129
default :
121
130
err = srv .Send (& ab.BroadcastResponse {Status : cb .Status_SERVICE_UNAVAILABLE })
0 commit comments