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 SDLWelcome {
    uint32 version = 1;
    uint32 max_bidi_streams = 2;
    uint32 max_packet_size = 3;
    uint32 heartbeat_sec = 4;
    SDLV6Info ipv6_assist = 5;
}

message SDLRegisterSuper {
    string client_id = 1;
    uint32 network_id = 2;
    bytes mac = 3;
    uint32 ip = 4;
    uint32 mask_len = 5;
    string hostname = 6;
    string pub_key = 7;
    string access_token = 8;
}

message SDLRegisterSuperAck {
    string algorithm = 1;
    bytes key = 2;
    uint32 region_id = 3;
    bytes session_token = 4;
}

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

// 网络地址查询
message SDLQueryInfo {
    bytes dst_mac = 1;
}

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

message SDLArpRequest {
    uint32 target_ip = 1;
    uint32 origin_ip = 2;
    bytes context = 3;
}

message SDLArpResponse {
    uint32 target_ip = 1;
    bytes target_mac = 2;
    uint32 origin_ip = 3;
    bytes context = 4;
}

message SDLPolicyRequest {
    uint32 src_identity_id = 1;
    uint32 dst_identity_id = 2;
    uint32 version = 3;
}

message SDLPolicyResponse {
    uint32 src_identity_id = 1;
    uint32 dst_identity_id = 2;
    uint32 version = 3;
    bytes rules = 4;
}

message SDLExposedServiceRequest {
    uint32 version = 1;
}

message SDLExposedServiceResponse {
    uint32 version = 1;
    repeated uint32 tcp_ports = 2;
    repeated uint32 udp_ports = 3;
}

// 事件定义
message SDLEvent {
    message NatChanged {
        bytes mac = 1;
        uint32 ip = 2;
    }

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

    message ExposedServiceChanged {
    }

    message NetworkShutdown {
        string message = 1;
    }

    oneof event {
        NatChanged nat_changed = 1;
        SendRegister send_register = 2;
        NetworkShutdown shutdown = 3;
        ExposedServiceChanged exposed_service_changed = 4;
    }
}

// 命令定义
message SDLCommand {
    uint32 pkt_id = 1;

    message ExitNodeControl {
        int32 action = 1;
        string remark = 2;
    }

    oneof command {
        ExitNodeControl exit_node = 2;
    }
}

message SDLCommandAck {
    uint32 pkt_id = 1;
    int32 code = 2;
    string message = 3;
    bytes data = 4;
}

// UDP通讯消息
message SDLStunRequest {
    string client_id = 1;
    uint32 network_id = 2;
    bytes mac = 3;
    uint32 ip = 4;
    uint32 nat_type = 5;
    optional SDLV6Info v6_info = 6;
    bytes session_token = 7;
}

message SDLStunReply {
}

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

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;
    uint32 step = 3;
}

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