syntax = "proto3";

// ************ Important! ***************
//
// If you change anything here, you *must* run 'generate-protobuf' to update the
// generated stub files.
//
// Never change the existing members and member values of messages, only add new ones.

service Warp {
    // Sender methods
    // api v1 duplex method (ping style)
    rpc CheckDuplexConnection(LookupName) returns (HaveDuplex) {}
    // api v2 duplex method (block/future)
    rpc WaitingForDuplex(LookupName) returns (HaveDuplex) {}

    rpc GetRemoteMachineInfo(LookupName) returns (RemoteMachineInfo) {}
    rpc GetRemoteMachineAvatar(LookupName) returns (stream RemoteMachineAvatar) {}
    rpc ProcessTransferOpRequest(TransferOpRequest) returns (VoidType) {}
    rpc PauseTransferOp(OpInfo) returns (VoidType) {}

    // Receiver methods
    rpc StartTransfer(OpInfo) returns (stream FileChunk) {}

    // Both
    rpc CancelTransferOpRequest(OpInfo) returns (VoidType) {}
    rpc StopTransfer(StopInfo) returns (VoidType) {}

    rpc Ping(LookupName) returns (VoidType) {}
}

message RemoteMachineInfo {
    string display_name = 1;
    string user_name = 2;
}

message RemoteMachineAvatar {
    bytes avatar_chunk = 1;
}

message LookupName {
    string id = 1;
    string readable_name = 2;
}

message HaveDuplex {
    bool response = 2;
}

message VoidType {
    int32 dummy = 1;
}

message OpInfo {
    string ident = 1;
    uint64 timestamp = 2;
    string readable_name = 3;
    bool use_compression = 4;
}

message StopInfo {
    OpInfo info = 1;
    bool error = 2;
}

message TransferOpRequest {
    OpInfo info = 1;
    string sender_name = 2;
    string receiver_name = 3;
    string receiver = 4; // don't need for now
    uint64 size = 5;
    uint64 count = 6;
    string name_if_single = 7;
    string mime_if_single = 8;
    repeated string top_dir_basenames = 9;
}

message FileChunk {
    string relative_path = 1;
    int32 file_type = 2;
    string symlink_target = 3;
    bytes chunk = 4;
    uint32 file_mode = 5;
    FileTime time = 6;
}

message FileTime {
    uint64 mtime = 1;
    uint32 mtime_usec = 2;
}

service WarpRegistration {
    rpc RequestCertificate(RegRequest) returns (RegResponse) {}
}

message RegRequest {
    string ip = 1;
    string hostname = 2;
}

message RegResponse {
    string locked_cert = 1;
}
