// File: /workspace/github_cpp_makefile_star2_O2/xocoder[P]m_kcptun/src/kcp_remote.cpp
// Function: remote_udpin_callback(chann_msg_t*)
static void
_remote_udpin_callback(chann_msg_t *e) {
   tun_remote_t *tun = (tun_remote_t*)e->opaque;   

   switch (e->event) {

      case CHANN_EVENT_RECV: {
         long ret = mnet_chann_recv(e->n, tun->buf, MKCP_BUF_SIZE);

         if (ret >= MKCP_OVERHEAD) {
            const int rs_offset = tun->rt ? sizeof(uint16_t) : 0;
            uint8_t *data = tun->buf + rs_offset;
            int data_len = tun->rt ? rskcp_dec_info(tun->rt, ret) : (ret - XOR64_CHECKSUM_SIZE);

            if ( tun->rt ) {
               ret = rskcp_decode(tun->rt, tun->buf, ret, &tun->buf[data_len]);
               data_len = *((uint16_t*)tun->buf); // restore data_len
            } else {
               ret = xor64_checksum_check(data, data_len, &tun->buf[data_len]);
            }

            if ( ret ) {
               if ( tun->conf->crypto ) {
                  data_len = rc4_decrypt((const char*)data, data_len,
                                         (char*)tun->buf, MKCP_BUF_SIZE,
                                         tun->ukey, (tun->ti>>20));
                  if (data_len < 0) {
                     return;
                  }
                  data = tun->buf;
               }

               if (data_len >= MKCP_OVERHEAD) {
                  proto_t pr;
                  const uint8_t *proto_data = &data[MKCP_OVERHEAD];

                  if (proto_probe(proto_data, data_len - MKCP_OVERHEAD, &pr) &&
                      pr.ptype == PROTO_TYPE_CTRL &&
                      pr.u.cmd == PROTO_CMD_RESET &&
                      tun->kcpconv != ikcp_getconv(data))
                  {
                     _remote_kcpin_reset(tun, ikcp_getconv(data));
                  }

                  ikcp_input(tun->kcpin, (const char*)data, data_len);
                  break;
               }
            }
         }

         chann_addr_t addr;
         mnet_chann_addr(e->n, &addr);
         cout << "invalid udp packet from "
              << addr.ip << ":" << addr.port
              << " ret: " << ret << endl;
         break;
      }

      case CHANN_EVENT_DISCONNECT:  {
         cout << "remote udp disconnect !" << endl;
         mnet_chann_close(e->n);
         break;
      }

      default: {
         break;
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r12
movl (%rdi), %eax
cmpl $0x5, %eax
je 0x7afc
cmpl $0x1, %eax
jne 0x7cd0
movq 0x18(%r12), %r14
movq 0x8(%r12), %rdi
leaq 0x98(%r14), %rbx
movq %rbx, %rsi
movl $0x10000, %edx          # imm = 0x10000
callq 0x4890
movl %eax, %r13d
cmpl $0x18, %eax
jl 0x7c61
movq 0x90(%r14), %rdi
xorl %eax, %eax
testq %rdi, %rdi
setne %al
leaq (%rbx,%rax,2), %rcx
movq %rcx, -0x30(%rbp)
je 0x7b2f
movl %r13d, %esi
callq 0x825a
movq 0x90(%r14), %rdi
testq %rdi, %rdi
je 0x7b38
movslq %eax, %rcx
addq %rbx, %rcx
movq %rbx, %rsi
movl %r13d, %edx
callq 0x8341
movl %eax, %r13d
movzwl (%rbx), %r15d
jmp 0x7b51
movq 0x74cd(%rip), %rdi      # 0xefd0
leaq 0x3537(%rip), %rsi      # 0xb041
callq 0x2260
movq %rax, %rdi
callq 0x2140
movq 0x8(%r12), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42d4
addl $-0x8, %r13d
movl %r13d, %eax
jmp 0x7b3c
movq -0x30(%rbp), %rcx
movq %rax, %r15
movslq %eax, %rsi
leaq (%rbx,%rsi), %rdx
movq %rcx, %rdi
callq 0x574a
movl %eax, %r13d
testl %r13d, %r13d
je 0x7b8f
movq 0x78(%r14), %rax
cmpl $0x0, 0x148(%rax)
je 0x7b97
movq 0x60(%r14), %r8
movq 0x68(%r14), %r9
shrq $0x14, %r9
movq -0x30(%rbp), %rdi
movl %r15d, %esi
movq %rbx, %rdx
movl $0x10000, %ecx          # imm = 0x10000
callq 0x5571
movl %eax, %r15d
testl %eax, %eax
jns 0x7b9b
jmp 0x7cd0
xorl %r13d, %r13d
jmp 0x7c61
movq -0x30(%rbp), %rbx
cmpl $0x18, %r15d
jl 0x7c61
leaq 0x18(%rbx), %rdi
movq %r15, %r12
leal -0x18(%r15), %esi
leaq -0x48(%rbp), %rdx
callq 0x6974
testl %eax, %eax
je 0x7ced
cmpl $0x1, -0x48(%rbp)
jne 0x7ced
cmpb $0x4, -0x40(%rbp)
jne 0x7ced
movl 0x50(%r14), %r15d
movq %rbx, %rdi
callq 0x3c10
cmpl %eax, %r15d
je 0x7ced
movq %rbx, %rdi
callq 0x3c10
movl %eax, %r15d
movq 0x73d4(%rip), %rdi      # 0xefd0
leaq 0x3456(%rip), %rsi      # 0xb059
callq 0x2260
movl %r15d, %esi
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
callq 0x2140
movl %r15d, 0x50(%r14)
movq %r14, %rdi
callq 0x7e06
movq %r14, %rdi
callq 0x7cfe
movq 0x58(%r14), %rdi
callq 0x662e
movq 0x58(%r14), %rdi
testl %eax, %eax
jle 0x7cdf
callq 0x68a2
movq %rax, %r15
movq 0x8(%rax), %rdi
callq 0x42d4
xorl %edi, %edi
movq %r15, %rsi
callq 0x7639
jmp 0x7c2f
movslq %r13d, %rbx
movq 0x8(%r12), %rdi
leaq -0x48(%rbp), %r14
movq %r14, %rsi
callq 0x4d08
movq 0x7354(%rip), %rdi      # 0xefd0
leaq 0x339e(%rip), %rsi      # 0xb021
callq 0x2260
movq %rax, %rdi
movq %r14, %rsi
callq 0x2260
leaq 0x2ef7(%rip), %rsi      # 0xab91
movq %rax, %rdi
callq 0x2260
movl 0x10(%r14), %esi
movq %rax, %rdi
callq 0x23d0
leaq 0x3385(%rip), %rsi      # 0xb03a
movq %rax, %rdi
callq 0x2260
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2250
movq %rax, %rdi
callq 0x2140
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x65b2
callq 0x6504
movq %rax, 0x58(%r14)
movq 0x48(%r14), %rdi
movl %r12d, %edx
movq %rbx, %rsi
callq 0x2f49
jmp 0x7cd0