MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / StartClient

Method StartClient

agentprotocol/server.go:524–569  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

522}
523
524func (c *ForwardCtx) StartClient() (connectionType uint32, setupPacket SetupPacket, connChan chan *Connection, err error) {
525 c.init()
526
527 packet := Packet{}
528 err = c.decoder.Decode(&packet)
529 if err != nil {
530 c.logger.Warning("Failed to decode packet")
531 return 0, SetupPacket{}, nil, err
532 }
533 if packet.Type != PACKET_SETUP {
534 c.logger.Warning(
535 message.NewMessage(
536 message.EAgentPacketInvalid,
537 "Received packet type %d when expecting startup packet from agent",
538 packet.Type,
539 ),
540 )
541 return 0, SetupPacket{}, nil, fmt.Errorf("invalid packet type, expecting PACKET_SETUP")
542 }
543 setup, err := c.unmarshalSetup(packet.Payload)
544 if err != nil {
545 c.logger.Error(message.Wrap(
546 err,
547 message.EAgentDecodingFailed,
548 "Error unmarshalling setup packet",
549 ))
550 return 0, setup, nil, err
551 }
552
553 success := Packet{
554 Type: PACKET_SUCCESS,
555 }
556 err = c.writePacket(&success)
557 if err != nil {
558 c.logger.Error(message.Wrap(
559 err,
560 message.EAgentWriteFailed,
561 "Error writing success packet",
562 ))
563 return 0, setup, nil, err
564 }
565
566 go c.handleBackend()
567
568 return setup.ConnectionType, setup, c.connectionChannel, nil
569}
570
571func (c *ForwardCtx) StartServerForward() (chan *Connection, error) {
572 c.init()

Callers 1

TestConnectionSetupFunction · 0.95

Calls 10

initMethod · 0.95
unmarshalSetupMethod · 0.95
writePacketMethod · 0.95
handleBackendMethod · 0.95
NewMessageFunction · 0.92
WrapFunction · 0.92
DecodeMethod · 0.65
WarningMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.65

Tested by 1

TestConnectionSetupFunction · 0.76