//
// Aspia Project
// Copyright (C) 2016-2024 Dmitry Chapyshev <dmitry@aspia.ru>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

syntax = "proto3";

option optimize_for = LITE_RUNTIME;

import "router_common.proto";

package proto;

message HostIdRequest
{
    enum Type
    {
        UNKNOWN     = 0;
        NEW_ID      = 1;
        EXISTING_ID = 2;
    }

    Type type = 1;
    bytes key = 2;
}

message ResetHostId
{
    fixed64 host_id = 1;
}

message HostIdResponse
{
    enum ErrorCode
    {
        SUCCESS       = 0;
        UNKNOWN       = 1;
        NO_HOST_FOUND = 2;
    }

    fixed64 host_id      = 1;
    bytes key            = 2;
    ErrorCode error_code = 3;
}

message ConnectionRequest
{
    fixed64 host_id = 1;
}

message HostOfferData
{
    fixed64 host_id = 1; // ID to which the client will connect.
}

message ConnectionOffer
{
    enum PeerRole
    {
        HOST   = 0;
        CLIENT = 1;
    }

    enum ErrorCode
    {
        SUCCESS        = 0;
        UNKNOWN_ERROR  = 1;
        PEER_NOT_FOUND = 2;
        ACCESS_DENIED  = 3;
        KEY_POOL_EMPTY = 4;
    }

    PeerRole peer_role      = 1;
    ErrorCode error_code    = 2;
    RelayCredentials relay  = 3;
    HostOfferData host_data = 4;
}

message CheckHostStatus
{
    fixed64 host_id = 1;
}

message HostStatus
{
    enum Status
    {
        STATUS_UNKNOWN = 0;
        STATUS_OFFLINE = 1;
        STATUS_ONLINE  = 2;
    }

    Status status = 1;
}

message RouterToPeer
{
    HostIdResponse host_id_response  = 1;
    ConnectionOffer connection_offer = 2;
    HostStatus host_status           = 3;
}

message PeerToRouter
{
    ConnectionRequest connection_request = 1;
    HostIdRequest host_id_request        = 2;
    ResetHostId reset_host_id            = 3;
    CheckHostStatus check_host_status    = 4;
}
