syntax = "proto3";

package trojan.api;
option go_package = "github.com/p4gefau1t/trojan-go/api/service";

message Traffic {
    uint64 upload_traffic = 1;
    uint64 download_traffic = 2;
}

message Speed {
    uint64 upload_speed = 1;
    uint64 download_speed = 2;
}

message User {
    string password = 1;
    string hash = 2;
}

message UserStatus {
    User user = 1;
    Traffic traffic_total = 2;
    Speed speed_current = 3;
    Speed speed_limit = 4;
    int32 ip_current = 5;
    int32 ip_limit = 6;
}

message GetTrafficRequest {
    User user = 1;
}

message GetTrafficResponse {
    bool success = 1;
    string info = 2;
    Traffic traffic_total = 3;
    Speed speed_current = 4;
}

message ListUsersRequest {

}

message ListUsersResponse {
    UserStatus status = 1;
}

message GetUsersRequest {
    User user = 1;
}

message GetUsersResponse {
    bool success = 1;
    string info = 2;
    UserStatus status = 3;
}

message SetUsersRequest {
    enum Operation {
        Add = 0;
        Delete = 1;
        Modify = 2;
    }
    UserStatus status = 1;
    Operation operation = 2;
}

message SetUsersResponse {
    bool success = 1;
    string info = 2;
}

service TrojanClientService {
    rpc GetTraffic(GetTrafficRequest) returns(GetTrafficResponse){}
}

service TrojanServerService {
    // list all users
    rpc ListUsers(ListUsersRequest) returns(stream ListUsersResponse){}
    // obtain specified user's info
    rpc GetUsers(stream GetUsersRequest) returns(stream GetUsersResponse){}
    // setup existing users' config
    rpc SetUsers(stream SetUsersRequest) returns(stream SetUsersResponse){}
}
