@@ -66,7 +66,7 @@ type Discovery interface {
6666 // StartSync is called to put the discovery in event mode. When the
6767 // function returns the discovery must send port events ("add" or "remove")
6868 // using the eventCB function.
69- StartSync (eventCB EventCallback ) error
69+ StartSync (eventCB EventCallback , errorCB ErrorCallback ) error
7070
7171 // Stop stops the discovery internal subroutines. If the discovery is
7272 // in event mode it must stop sending events through the eventCB previously
@@ -83,6 +83,12 @@ type Discovery interface {
8383// is detected.
8484type EventCallback func (event string , port * Port )
8585
86+ // ErrorCallback is a callback function to signal unrecoverable errors to the
87+ // client while the discovery is in event mode. Once the discovery signal an
88+ // error it means that no more port-events will be delivered until the client
89+ // performs a STOP+START_SYNC cycle.
90+ type ErrorCallback func (err string )
91+
8692// A DiscoveryServer is a pluggable discovery protocol handler,
8793// it must be created using the NewDiscoveryServer function.
8894type DiscoveryServer struct {
@@ -233,7 +239,7 @@ func (d *DiscoveryServer) startSync() {
233239 }
234240 c := make (chan interface {}, 10 ) // buffer up to 10 events
235241 d .syncChannel = c
236- if err := d .impl .StartSync (d .syncEvent ); err != nil {
242+ if err := d .impl .StartSync (d .syncEvent , d . errorEvent ); err != nil {
237243 d .outputError ("start_sync" , "Cannot START_SYNC: " + err .Error ())
238244 close (d .syncChannel ) // do not leak channel...
239245 d .syncChannel = nil
@@ -278,6 +284,19 @@ func (d *DiscoveryServer) syncEvent(event string, port *Port) {
278284 }
279285}
280286
287+ func (d * DiscoveryServer ) errorEvent (msg string ) {
288+ type syncOutputJSON struct {
289+ EventType string `json:"eventType"`
290+ Error bool `json:"error"`
291+ Message string `json:"message"`
292+ }
293+ d .syncChannel <- & syncOutputJSON {
294+ EventType : "start_sync" ,
295+ Error : true ,
296+ Message : msg ,
297+ }
298+ }
299+
281300type genericMessageJSON struct {
282301 EventType string `json:"eventType"`
283302 Message string `json:"message"`
0 commit comments