syntax = "proto3";

option java_package = "com.jihe.punchnet.protobuf";
option java_outer_classname = "PunchProto";
// 基础公共类型定义

message SDLV4Info {
    uint32 port = 1;
    bytes v4 = 2;
    uint32 nat_type = 3;
}

message SDLV6Info {
    uint32 port = 1;
    bytes v6 = 2;
}

// 设备网络地址信息
message SDLDevAddr {
    uint32 network_id = 1;
    bytes mac = 2;
    uint32 net_addr = 3;
    uint32 net_bit_len = 4;
}

// tcp通讯消息
message SDLEmpty {

}

message SDLRegisterSuper {
    uint32 version = 1;
    string installed_channel = 2;
    string client_id = 3;
    SDLDevAddr dev_addr = 4;
    string pub_key = 5;
    string token = 6;
}

message SDLRegisterSuperAck {
    SDLDevAddr dev_addr = 1;
    bytes aes_key = 2;
    uint32 upgrade_type = 3;
    optional string upgrade_prompt = 4;
    optional string upgrade_address = 5;
}

message SDLRegisterSuperNak {
    uint32 error_code = 1;
    string error_message = 2;
}

// 网络地址查询

message SDLQueryInfo {
    bytes dst_mac = 1;
}

message SDLPeerInfo {
    bytes dst_mac = 1;
    SDLV4Info v4_info = 2;
    optional SDLV6Info v6_info = 3;
}

// 事件定义

message SDLNatChangedEvent {
    bytes mac = 1;
    uint32 ip = 2;
}

message SDLSendRegisterEvent {
    bytes dst_mac = 1;
    uint32 nat_ip = 2;
    uint32 nat_port = 3;
    uint32 nat_type = 4;
    optional SDLV6Info v6_info = 5;
}

message SDLNetworkShutdownEvent {
    string message = 1;
}

// 命令定义

message SDLChangeNetworkCommand {
    SDLDevAddr dev_addr = 1;
    bytes aes_key = 2;
}

message SDLCommandAck {
    // status = true, 表示成功；status = false 表示失败，message是失败原因描述 
    bool status = 1;
    optional string message = 2;
}

message SDLFlows {
    // 服务器转发流量
    uint32 forward_num = 1;
    // p2p直接流量
    uint32 p2p_num = 2;
    // 接收的流量
    uint32 inbound_num = 3;
}

// UDP通讯消息

message SDLStunRequest {
    uint32 cookie = 1;
    string client_id = 2;
    uint32 network_id = 3;
    bytes mac = 4;
    uint32 ip = 5;
    uint32 nat_type = 6;
    optional SDLV6Info v6_info = 7;
}

message SDLStunReply {
    uint32 cookie = 1;
}

message SDLData {
    uint32 network_id = 1;
    bytes src_mac = 2;
    bytes dst_mac = 3;
    bool is_p2p = 4;
    uint32 ttl = 5;
    bytes data = 6;
}

message SDLRegister {
    uint32 network_id = 1;
    bytes src_mac = 2;
    bytes dst_mac = 3;
}

message SDLRegisterAck {
    uint32 network_id = 1;
    bytes src_mac = 2;
    bytes dst_mac = 3;
}

// 网络类型探测

message SDLStunProbe {
    uint32 cookie = 1;
    uint32 attr = 2;
}

message SDLStunProbeReply {
    uint32 cookie = 1;
    uint32 port = 2;
    uint32 ip = 3;
}