func (o *Command) Connections(rw io.Writer, req io.Reader) command.Error {
	connections, err := o.routeClient.GetConnections()
	if err != nil {
		logutil.LogError(logger, CommandName, GetConnectionsCommandMethod, err.Error())
		return command.NewExecuteError(GetConnectionsErrorCode, err)
	}
	command.WriteNillableResponse(rw, &ConnectionsResponse{
		Connections: connections,
	}, logger)
	logutil.LogDebug(logger, CommandName, GetConnectionsCommandMethod, successString)
	return nil
}
Connections returns the connections of the router.
package mediator
import (
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"github.com/hyperledger/aries-framework-go/pkg/client/mediator"
	"github.com/hyperledger/aries-framework-go/pkg/client/messagepickup"
	"github.com/hyperledger/aries-framework-go/pkg/client/outofband"
	"github.com/hyperledger/aries-framework-go/pkg/common/log"
	"github.com/hyperledger/aries-framework-go/pkg/controller/command"
	"github.com/hyperledger/aries-framework-go/pkg/controller/internal/cmdutil"
	"github.com/hyperledger/aries-framework-go/pkg/didcomm/common/service"
	"github.com/hyperledger/aries-framework-go/pkg/internal/logutil"
	"github.com/hyperledger/aries-framework-go/pkg/kms"
)
var logger = log.New("aries-framework/command/route")
const (
	InvalidRequestErrorCode = command.Code(iota + command.ROUTE)
	RegisterMissingConnIDCode
	RegisterRouterErrorCode
	UnregisterRouterErrorCode
	GetConnectionsErrorCode
	ReconnectMissingConnIDCode
	ReconnectRouterErrorCode
	StatusRequestMissingConnIDCode
	StatusRequestErrorCode
	BatchPickupMissingConnIDCode
	BatchPickupRequestErrorCode
	ReconnectAllError
)
const (
	CommandName = "mediator"
	RegisterCommandMethod       = "Register"
	UnregisterCommandMethod     = "Unregister"
	GetConnectionsCommandMethod = "Connections"
	ReconnectCommandMethod      = "Reconnect"
	StatusCommandMethod         = "Status"
	BatchPickupCommandMethod    = "BatchPickup"
	ReconnectAllCommandMethod   = "ReconnectAll"
	connectionID  = "connectionID"
	successString = "success"
)
type provider interface {
	Service(id string) (interface{}, error)
	KMS() kms.KeyManager
	ServiceEndpoint() string
	KeyType() kms.KeyType
	KeyAgreementType() kms.KeyType
	MediaTypeProfiles() []string
}
type Command struct {
	routeClient   *mediator.Client
	messageClient *messagepickup.Client
	outOfBand     *outofband.Client
}
func New(ctx provider, autoAccept bool) (*Command, error) {
	routeClient, err := mediator.New(ctx)
	if err != nil {
		return nil, fmt.Errorf("create route client : %w", err)
	}
	if !autoAccept {
		autoAccept = true
	}
	if autoAccept {
		actions := make(chan service.DIDCommAction)
		err = routeClient.RegisterActionEvent(actions)
		if err != nil {
			return nil, fmt.Errorf("failed to register action events : %w", err)
		}
		go service.AutoExecuteActionEvent(actions)
	}
	messageClient, err := messagepickup.New(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to create message client : %w", err)
	}
	outOfBandClient, err := outofband.New(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to create out-of-band client : %w", err)
	}
	return &Command{
		routeClient:   routeClient,
		messageClient: messageClient,
		outOfBand:     outOfBandClient,
	}, nil
}
func (o *Command) GetHandlers() []command.Handler {
	return []command.Handler{
		cmdutil.NewCommandHandler(CommandName, RegisterCommandMethod, o.Register),
		cmdutil.NewCommandHandler(CommandName, UnregisterCommandMethod, o.Unregister),
		cmdutil.NewCommandHandler(CommandName, GetConnectionsCommandMethod, o.Connections),
		cmdutil.NewCommandHandler(CommandName, ReconnectCommandMethod, o.Reconnect),
		cmdutil.NewCommandHandler(CommandName, ReconnectAllCommandMethod, o.ReconnectAll),
		cmdutil.NewCommandHandler(CommandName, StatusCommandMethod, o.Status),
		cmdutil.NewCommandHandler(CommandName, BatchPickupCommandMethod, o.BatchPickup),
	}
}
func (o *Command) Register(rw io.Writer, req io.Reader) command.Error {
	var request RegisterRoute
	err := json.NewDecoder(req).Decode(&request)
	if err != nil {
		logutil.LogInfo(logger, CommandName, RegisterCommandMethod, err.Error())
		return command.NewValidationError(InvalidRequestErrorCode, fmt.Errorf("request decode : %w", err))
	}
	if request.ConnectionID == "" {
		logutil.LogDebug(logger, CommandName, RegisterCommandMethod, "missing connectionID",
			logutil.CreateKeyValueString(connectionID, request.ConnectionID))
		return command.NewValidationError(RegisterMissingConnIDCode, errors.New("connectionID is mandatory"))
	}
	err = o.routeClient.Register(request.ConnectionID)
	if err != nil {
		logutil.LogError(logger, CommandName, RegisterCommandMethod, err.Error(),
			logutil.CreateKeyValueString(connectionID, request.ConnectionID))
		return command.NewExecuteError(RegisterRouterErrorCode, err)
	}
	command.WriteNillableResponse(rw, nil, logger)
	logutil.LogDebug(logger, CommandName, RegisterCommandMethod, successString,
		logutil.CreateKeyValueString(connectionID, request.ConnectionID))
	return nil
}
func (o *Command) Unregister(rw io.Writer, req io.Reader) command.Error {
	var request RegisterRoute
	err := json.NewDecoder(req).Decode(&request)
	if err != nil {
		logutil.LogInfo(logger, CommandName, UnregisterCommandMethod, err.Error())
		return command.NewValidationError(InvalidRequestErrorCode, fmt.Errorf("request decode : %w", err))
	}
	if request.ConnectionID == "" {
		logutil.LogDebug(logger, CommandName, UnregisterCommandMethod, "missing connectionID",
			logutil.CreateKeyValueString(connectionID, request.ConnectionID))
		return command.NewValidationError(UnregisterRouterErrorCode, errors.New("connectionID is mandatory"))
	}
	err = o.routeClient.Unregister(request.ConnectionID)
	if err != nil {
		logutil.LogError(logger, CommandName, UnregisterCommandMethod, err.Error())
		return command.NewExecuteError(UnregisterRouterErrorCode, err)
	}
	command.WriteNillableResponse(rw, nil, logger)
	logutil.LogDebug(logger, CommandName, UnregisterCommandMethod, successString)
	return nil
}