MCPcopy Create free account
hub / github.com/CPChain/chain / StartWSEndpoint

Function StartWSEndpoint

api/rpc/endpoints.go:55–83  ·  view source on GitHub ↗

StartWSEndpoint starts a websocket endpoint

(endpoint string, apis []API, modules []string, wsOrigins []string, exposeAll bool)

Source from the content-addressed store, hash-verified

53
54// StartWSEndpoint starts a websocket endpoint
55func StartWSEndpoint(endpoint string, apis []API, modules []string, wsOrigins []string, exposeAll bool) (net.Listener, *Server, error) {
56
57 // Generate the whitelist based on the allowed modules
58 whitelist := make(map[string]bool)
59 for _, module := range modules {
60 whitelist[module] = true
61 }
62 // Register all the APIs exposed by the services
63 handler := NewServer()
64 for _, api := range apis {
65 if exposeAll || whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) {
66 if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
67 return nil, nil, err
68 }
69 log.Debug("WebSocket registered", "service", api.Service, "namespace", api.Namespace)
70 }
71 }
72 // All APIs registered, start the HTTP listener
73 var (
74 listener net.Listener
75 err error
76 )
77 if listener, err = net.Listen("tcp", endpoint); err != nil {
78 return nil, nil, err
79 }
80 go NewWSServer(wsOrigins, handler).Serve(listener)
81 return listener, handler, err
82
83}
84
85// StartIPCEndpoint starts an IPC endpoint.
86func StartIPCEndpoint(ipcEndpoint string, apis []API) (net.Listener, *Server, error) {

Callers

nothing calls this directly

Calls 4

RegisterNameMethod · 0.95
NewServerFunction · 0.85
NewWSServerFunction · 0.85
DebugMethod · 0.80

Tested by

no test coverage detected