(ctx context.Context, data *common.Backend)
| 10 | ) |
| 11 | |
| 12 | func (s *Service) Start(ctx context.Context, data *common.Backend) (*common.BaseInfoResponse, error) { |
| 13 | clientIP := "" |
| 14 | if p, ok := peer.FromContext(ctx); ok { |
| 15 | // Extract IP address from peer address |
| 16 | if tcpAddr, ok := p.Addr.(*net.TCPAddr); ok { |
| 17 | clientIP = tcpAddr.IP.String() |
| 18 | } else { |
| 19 | // For other address types, extract just the IP without the port |
| 20 | addr := p.Addr.String() |
| 21 | if host, _, err := net.SplitHostPort(addr); err == nil { |
| 22 | clientIP = host |
| 23 | } else { |
| 24 | // If SplitHostPort fails, use the whole address |
| 25 | clientIP = addr |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | if s.Backend() != nil { |
| 31 | log.Println("New connection from ", clientIP, " core control access was taken away from previous client.") |
| 32 | s.Disconnect() |
| 33 | } |
| 34 | |
| 35 | if err := s.StartBackend(ctx, data); err != nil { |
| 36 | return nil, err |
| 37 | } |
| 38 | |
| 39 | s.Connect(clientIP, data.GetKeepAlive()) |
| 40 | |
| 41 | return s.BaseInfoResponse(), nil |
| 42 | } |
| 43 | |
| 44 | func (s *Service) Stop(_ context.Context, _ *common.Empty) (*common.Empty, error) { |
| 45 | s.Disconnect() |
nothing calls this directly
no test coverage detected