// File: theuni[P]libbtcnet/src/handler.cpp
// Function: CConnectionHandlerInt::Start(int)
void CConnectionHandlerInt::Start(int outgoing_limit)
{
    int result = 0;
    m_shutdown = false;

#ifndef NO_THREADS
    if (m_enable_threading)
        m_main_thread = std::this_thread::get_id();
#endif

    assert(m_outgoing_conn_count == 0);
    assert(m_incoming_conn_count == 0);
    assert(!m_event_base);
    assert(!m_dns_base);
    assert(!m_request_event);
    assert(!m_shutdown_event);

    m_outgoing_conn_limit = outgoing_limit;

    event_type<event_config> cfg(event_config_new());
    result = event_config_set_flag(cfg, EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST);
    assert(result == 0);
    (void)result;

    m_event_base = event_base_new_with_config(cfg);

    if (m_enable_threading) {
        result = enable_threads_for_handler(m_event_base);
        assert(result == 0);
        (void)result;
    }
    cfg.free();

    m_dns_base = evdns_base_new(m_event_base, 1);
    result = evdns_base_set_option(m_dns_base, "randomize-case", "0");
    assert(result == 0);
    (void)result;

    event_base_priority_init(m_event_base, 3);

    m_request_event.reset(m_event_base, -1, EV_PERSIST, std::bind(&CConnectionHandlerInt::RequestOutgoingInt, this));
    m_shutdown_event.reset(m_event_base, -1, 0, std::bind(&CConnectionHandlerInt::ShutdownInt, this));

    m_shutdown_event.priority_set(0);

    m_outgoing_rate_cfg = ev_token_bucket_cfg_new(EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, nullptr);
    m_incoming_rate_cfg = ev_token_bucket_cfg_new(EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, EV_RATE_LIMIT_MAX, nullptr);

    m_outgoing_rate_limit = bufferevent_rate_limit_group_new(m_event_base, m_outgoing_rate_cfg);
    m_incoming_rate_limit = bufferevent_rate_limit_group_new(m_event_base, m_incoming_rate_cfg);

    timeval request_timeout = {0, 500000};
    m_request_event.add(&request_timeout);
    m_interface.OnStartup();

    m_request_event.active();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movl $0x0, -0x10(%rbp)
movb $0x0, 0xed(%rax)
testb $0x1, 0xec(%rax)
je 0xd8a2
callq 0x10d90
movq %rax, %rcx
movq -0xe8(%rbp), %rax
movq %rcx, -0x18(%rbp)
movq -0x18(%rbp), %rcx
movq %rcx, 0x168(%rax)
movq -0xe8(%rbp), %rax
cmpl $0x0, 0xe0(%rax)
jne 0xd8b4
jmp 0xd8d3
leaq 0x17f2d(%rip), %rdi     # 0x257e8
leaq 0x17ecd(%rip), %rsi     # 0x2578f
movl $0x35, %edx
leaq 0x17f35(%rip), %rcx     # 0x25803
callq 0x52e0
movq -0xe8(%rbp), %rax
cmpl $0x0, 0xe4(%rax)
jne 0xd8e5
jmp 0xd904
leaq 0x17f3e(%rip), %rdi     # 0x2582a
leaq 0x17e9c(%rip), %rsi     # 0x2578f
movl $0x36, %edx
leaq 0x17f04(%rip), %rcx     # 0x25803
callq 0x52e0
movq -0xe8(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
callq 0x10dc0
testb $0x1, %al
jne 0xd91d
jmp 0xd91f
jmp 0xd93e
leaq 0x17f1f(%rip), %rdi     # 0x25845
leaq 0x17e62(%rip), %rsi     # 0x2578f
movl $0x37, %edx
leaq 0x17eca(%rip), %rcx     # 0x25803
callq 0x52e0
movq -0xe8(%rbp), %rdi
addq $0x198, %rdi            # imm = 0x198
callq 0x10de0
testb $0x1, %al
jne 0xd957
jmp 0xd959
jmp 0xd978
leaq 0x17ef3(%rip), %rdi     # 0x25853
leaq 0x17e28(%rip), %rsi     # 0x2578f
movl $0x38, %edx
leaq 0x17e90(%rip), %rcx     # 0x25803
callq 0x52e0
movq -0xe8(%rbp), %rdi
addq $0x1a0, %rdi            # imm = 0x1A0
callq 0x239f0
xorb $-0x1, %al
testb $0x1, %al
jne 0xd993
jmp 0xd995
jmp 0xd9b4
leaq 0x17ec3(%rip), %rdi     # 0x2585f
leaq 0x17dec(%rip), %rsi     # 0x2578f
movl $0x39, %edx
leaq 0x17e54(%rip), %rcx     # 0x25803
callq 0x52e0
movq -0xe8(%rbp), %rdi
addq $0x1c8, %rdi            # imm = 0x1C8
callq 0x239f0
xorb $-0x1, %al
testb $0x1, %al
jne 0xd9cf
jmp 0xd9d1
jmp 0xd9f0
leaq 0x17e98(%rip), %rdi     # 0x25870
leaq 0x17db0(%rip), %rsi     # 0x2578f
movl $0x3a, %edx
leaq 0x17e18(%rip), %rcx     # 0x25803
callq 0x52e0
movq -0xe8(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, 0xe8(%rax)
callq 0x5690
movq %rax, %rsi
leaq -0x20(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x10e00
movq -0xf8(%rbp), %rdi
callq 0x10e50
movq %rax, -0xf0(%rbp)
jmp 0xda2d
movq -0xf0(%rbp), %rdi
movl $0x10, %esi
callq 0x5700
movl %eax, -0xfc(%rbp)
jmp 0xda46
movl -0xfc(%rbp), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0xda57
jmp 0xda87
leaq 0x17e24(%rip), %rdi     # 0x25882
leaq 0x17d2a(%rip), %rsi     # 0x2578f
movl $0x40, %edx
leaq 0x17d92(%rip), %rcx     # 0x25803
callq 0x52e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0xdf6f
leaq -0x20(%rbp), %rdi
callq 0x10e50
movq %rax, -0x108(%rbp)
jmp 0xda99
movq -0x108(%rbp), %rdi
callq 0x5570
movq %rax, -0x110(%rbp)
jmp 0xdaae
movq -0x110(%rbp), %rsi
movq -0xe8(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
callq 0x10ea0
jmp 0xdaca
movq -0xe8(%rbp), %rax
testb $0x1, 0xec(%rax)
je 0xdb27
movq -0xe8(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
callq 0xdf90
movl %eax, -0x114(%rbp)
jmp 0xdaf5
movl -0x114(%rbp), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0xdb06
jmp 0xdb25
leaq 0x17d75(%rip), %rdi     # 0x25882
leaq 0x17c7b(%rip), %rsi     # 0x2578f
movl $0x47, %edx
leaq 0x17ce3(%rip), %rcx     # 0x25803
callq 0x52e0
jmp 0xdb27
leaq -0x20(%rbp), %rdi
callq 0x10f00
jmp 0xdb32
movq -0xe8(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
callq 0x10f40
movq %rax, -0x120(%rbp)
jmp 0xdb4e
movq -0x120(%rbp), %rdi
movl $0x1, %esi
callq 0x5800
movq %rax, -0x128(%rbp)
jmp 0xdb68
movq -0x128(%rbp), %rsi
movq -0xe8(%rbp), %rdi
addq $0x198, %rdi            # imm = 0x198
callq 0x10f90
jmp 0xdb84
movq -0xe8(%rbp), %rdi
addq $0x198, %rdi            # imm = 0x198
callq 0x10ff0
movq %rax, -0x130(%rbp)
jmp 0xdba0
movq -0x130(%rbp), %rdi
leaq 0x17ce0(%rip), %rsi     # 0x2588e
leaq 0x18d05(%rip), %rdx     # 0x268ba
callq 0x52c0
movl %eax, -0x134(%rbp)
jmp 0xdbc2
movl -0x134(%rbp), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0xdbd3
jmp 0xdbf2
leaq 0x17ca8(%rip), %rdi     # 0x25882
leaq 0x17bae(%rip), %rsi     # 0x2578f
movl $0x4e, %edx
leaq 0x17c16(%rip), %rcx     # 0x25803
callq 0x52e0
movq -0xe8(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
callq 0x10f40
movq %rax, -0x140(%rbp)
jmp 0xdc0e
movq -0x140(%rbp), %rdi
movl $0x3, %esi
callq 0x5660
jmp 0xdc21
movq -0xe8(%rbp), %rax
movq %rax, %rcx
addq $0x1a0, %rcx            # imm = 0x1A0
movq %rcx, -0x150(%rbp)
movq %rax, %rcx
addq $0x190, %rcx            # imm = 0x190
movq %rcx, -0x148(%rbp)
leaq 0x36f(%rip), %rcx       # 0xdfc0
movq %rcx, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
movq %rax, -0x80(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x11040
jmp 0xdc74
leaq -0x50(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x11080
jmp 0xdc83
movq -0x148(%rbp), %rsi
movq -0x150(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x10, %ecx
leaq -0x50(%rbp), %r8
callq 0x238a0
jmp 0xdca6
leaq -0x50(%rbp), %rdi
callq 0x11120
movq -0xe8(%rbp), %rax
movq %rax, %rcx
addq $0x1c8, %rcx            # imm = 0x1C8
movq %rcx, -0x160(%rbp)
movq %rax, %rcx
addq $0x190, %rcx            # imm = 0x190
movq %rcx, -0x158(%rbp)
leaq 0x471(%rip), %rcx       # 0xe150
movq %rcx, -0xc8(%rbp)
movq $0x0, -0xc0(%rbp)
movq %rax, -0xd0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
callq 0x11040
jmp 0xdd14
leaq -0xa0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x11080
jmp 0xdd29
movq -0x158(%rbp), %rsi
movq -0x160(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
leaq -0xa0(%rbp), %r8
callq 0x238a0
jmp 0xdd4c
leaq -0xa0(%rbp), %rdi
callq 0x11120
movq -0xe8(%rbp), %rdi
addq $0x1c8, %rdi            # imm = 0x1C8
xorl %esi, %esi
callq 0x23b60
jmp 0xdd6f
xorl %eax, %eax
movl %eax, %r8d
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, %rdi
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x5640
movq %rax, -0x168(%rbp)
jmp 0xdd95
movq -0x168(%rbp), %rsi
movq -0xe8(%rbp), %rdi
addq $0x178, %rdi            # imm = 0x178
callq 0x11140
jmp 0xddb1
xorl %eax, %eax
movl %eax, %r8d
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, %rdi
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x5640
movq %rax, -0x170(%rbp)
jmp 0xddd7
movq -0x170(%rbp), %rsi
movq -0xe8(%rbp), %rdi
addq $0x170, %rdi            # imm = 0x170
callq 0x11140
jmp 0xddf3
movq -0xe8(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
callq 0x10f40
movq %rax, -0x178(%rbp)
jmp 0xde0f
movq -0xe8(%rbp), %rdi
addq $0x178, %rdi            # imm = 0x178
callq 0x111a0
movq %rax, -0x180(%rbp)
jmp 0xde2b
movq -0x180(%rbp), %rsi
movq -0x178(%rbp), %rdi
callq 0x5260
movq %rax, -0x188(%rbp)
jmp 0xde47
movq -0x188(%rbp), %rsi
movq -0xe8(%rbp), %rdi
addq $0x188, %rdi            # imm = 0x188
callq 0x111f0
jmp 0xde63
movq -0xe8(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
callq 0x10f40
movq %rax, -0x190(%rbp)
jmp 0xde7f
movq -0xe8(%rbp), %rdi
addq $0x170, %rdi            # imm = 0x170
callq 0x111a0
movq %rax, -0x198(%rbp)
jmp 0xde9b
movq -0x198(%rbp), %rsi
movq -0x190(%rbp), %rdi
callq 0x5260
movq %rax, -0x1a0(%rbp)
jmp 0xdeb7
movq -0x1a0(%rbp), %rsi
movq -0xe8(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
callq 0x111f0
jmp 0xded3
movq -0xe8(%rbp), %rdi
movups 0x1841f(%rip), %xmm0    # 0x26300
movaps %xmm0, -0xe0(%rbp)
addq $0x1a0, %rdi            # imm = 0x1A0
leaq -0xe0(%rbp), %rsi
callq 0x23b10
jmp 0xdefd
movq -0xe8(%rbp), %rax
movq 0xc0(%rax), %rdi
movq (%rdi), %rax
movq 0xa0(%rax), %rax
callq *%rax
jmp 0xdf19
movq -0xe8(%rbp), %rdi
addq $0x1a0, %rdi            # imm = 0x1A0
callq 0x23ac0
jmp 0xdf2e
leaq -0x20(%rbp), %rdi
callq 0x11250
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x11120
jmp 0xdf6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x11120
leaq -0x20(%rbp), %rdi
callq 0x11250
movq -0x28(%rbp), %rdi
callq 0x5710
nopw %cs:(%rax,%rax)