MCPcopy
hub / github.com/canopy-network/canopy / PluginConnectSync

Method PluginConnectSync

controller/controller.go:276–303  ·  view source on GitHub ↗

PluginConnectSync() blocking: enables a unix socket file where plugins can interact with the Canopy FSM

()

Source from the content-addressed store, hash-verified

274
275// PluginConnectSync() blocking: enables a unix socket file where plugins can interact with the Canopy FSM
276func (c *Controller) PluginConnectSync() {
277 sockPath := filepath.Join(socketDir, socketFile)
278 // make the path
279 if err := os.MkdirAll(socketDir, 0777); err != nil {
280 c.log.Fatalf("Failed to make the plugin socket path %s: %v", sockPath, err)
281 }
282 // clean old socket
283 if err := os.RemoveAll(sockPath); err != nil {
284 c.log.Fatalf("Failed to remove plugin socket %s: %v", sockPath, err)
285 }
286 // create a unix listener
287 l, err := net.Listen("unix", sockPath)
288 if err != nil {
289 c.log.Fatalf("Failed to listen on socket: %v", err)
290 }
291 defer l.Close()
292 // log the listener
293 c.log.Infof("Plugin service listening on socket: %s", sockPath)
294 // wait for a connection
295 conn, e := l.Accept()
296 if e != nil {
297 c.log.Fatalf("Failed to accept plugin connection: %v", e)
298 }
299 // create plugin object
300 c.Plugin = lib.NewPlugin(conn, c.log, time.Duration(c.Config.PluginTimeoutMS)*time.Millisecond)
301 // set plugin in FSM and mempool FSM
302 c.FSM.Plugin, c.Mempool.FSM.Plugin = c.Plugin, c.Plugin
303}
304
305// INTERNAL CALLS BELOW
306

Callers 1

NewFunction · 0.80

Calls 5

NewPluginFunction · 0.92
ListenMethod · 0.80
FatalfMethod · 0.65
CloseMethod · 0.65
InfofMethod · 0.65

Tested by

no test coverage detected