MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / NewBridge

Function NewBridge

internal/bridge/bridge.go:48–86  ·  view source on GitHub ↗

NewBridge creates a new bridge from the given configuration.

(cfg *config.C2BridgeConfig)

Source from the content-addressed store, hash-verified

46
47// NewBridge creates a new bridge from the given configuration.
48func NewBridge(cfg *config.C2BridgeConfig) (*Bridge, error) {
49 authCfg, err := mtls.ReadConfig(cfg.AuthFile)
50 if err != nil {
51 return nil, err
52 }
53
54 addr := authCfg.Address()
55 if cfg.ServerAddr != "" {
56 addr = cfg.ServerAddr
57 }
58
59 options, err := mtls.GetGrpcOptions(
60 []byte(authCfg.CACertificate),
61 []byte(authCfg.Certificate),
62 []byte(authCfg.PrivateKey),
63 authCfg.Type,
64 )
65 if err != nil {
66 return nil, err
67 }
68
69 conn, err := grpc.DialContext(context.Background(), addr, options...)
70 if err != nil {
71 return nil, err
72 }
73
74 ctx, cancel := context.WithCancel(context.Background())
75 return &Bridge{
76 cfg: cfg,
77 rpc: listenerrpc.NewListenerRPCClient(conn),
78 conn: conn,
79 listenerID: cfg.ListenerName,
80 pipelineID: cfg.PipelineName,
81 registry: buildDefaultRegistry(),
82 taskManager: NewTaskManager(),
83 ctx: ctx,
84 cancel: cancel,
85 }, nil
86}
87
88// Start registers the listener and pipeline, opens streams, and begins processing.
89func (b *Bridge) Start(ctx context.Context) error {

Callers 1

startBridgeFunction · 0.92

Calls 2

buildDefaultRegistryFunction · 0.85
NewTaskManagerFunction · 0.85

Tested by

no test coverage detected