func()

in dev-tools/v2tool/server/tool.go [95:126]


func (tool *Tool) writeConnInfo() error {
	log := logp.L()
	services := []proto.ConnInfoServices{proto.ConnInfoServices_CheckinV2}
	token, err := uuid.NewV4()
	if err != nil {
		return fmt.Errorf("error generating token: %w", err)
	}

	addr := fmt.Sprintf(":%d", tool.srv.Port)
	connInfo := &proto.ConnInfo{
		Addr:       addr,
		ServerName: tool.serverName,
		Token:      token.String(),
		CaCert:     tool.ca.Crt(),
		PeerCert:   tool.pair.Crt,
		PeerKey:    tool.pair.Key,
		Services:   services,
	}
	log.Debugf("Creating config for client with address %s and services: %v", connInfo.Addr, connInfo.Services)

	infoBytes, err := protobuf.Marshal(connInfo)
	if err != nil {
		return fmt.Errorf("failed to marshal connection information: %w", err)
	}

	err = tool.manager.WriteToClient(infoBytes)
	if err != nil {
		return fmt.Errorf("error writing connection info to client: %w", err)
	}

	return nil
}