// File: /workspace/github_cpp_makefile_star2_O2/luisremis[P]SDFS/Membership.cpp
// Function: Membership::Membership(bool, int)
Membership::Membership(bool introducer, int port)
{
	logFile.open("logMembership.log");

	isIntroducer = introducer;
	this->port = port;
	leader.active = false;

	sockfd = bindSocket(port);

    if(isIntroducer){
        logFile << "I am the introducer! " << std::endl;
        getAdress("Address.add");
    }
    else{
        getAdress("AddrIntro.add");
    }

    roundLock.lock();
    roundId = 0;
    roundLock.unlock();

    join();

    std::thread th3(&Membership::forJoinThread, this);
    std::thread th1(&Membership::listeningThread, this);
    std::thread th2(&Membership::detectThread, this);

    listening.swap(th1);
    detecting.swap(th2);
    joinThread.swap(th3);

    killListeningThread = false;
	killDetectingThread = false;

	//runLeaderElection();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, %rbx
callq 0x4570
leaq 0x280(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x260(%rbx)
movups %xmm0, 0x250(%rbx)
movups %xmm0, 0x240(%rbx)
movups %xmm0, 0x230(%rbx)
movups %xmm0, 0x220(%rbx)
movups %xmm0, 0x210(%rbx)
movups %xmm0, 0x200(%rbx)
movq %rax, 0x270(%rbx)
andq $0x0, 0x278(%rbx)
xorl %eax, %eax
movb %al, 0x280(%rbx)
movups %xmm0, 0x2a0(%rbx)
movups %xmm0, 0x2b0(%rbx)
andq $0x0, 0x2c0(%rbx)
leaq 0x2e8(%rbx), %rcx
movq %rcx, 0x2d8(%rbx)
andq $0x0, 0x2e0(%rbx)
movb %al, 0x2e8(%rbx)
leaq 0x398(%rbx), %r14
movups %xmm0, 0x2f8(%rbx)
movups %xmm0, 0x308(%rbx)
movups %xmm0, 0x318(%rbx)
movups %xmm0, 0x328(%rbx)
movups %xmm0, 0x338(%rbx)
andq $0x0, 0x348(%rbx)
movups %xmm0, 0x388(%rbx)
movups %xmm0, 0x378(%rbx)
movups %xmm0, 0x368(%rbx)
movups %xmm0, 0x358(%rbx)
movq %r14, %rdi
callq 0x4460
leaq 0xa069(%rip), %rsi      # 0xf3b0
pushq $0x10
popq %rdx
movq %rbx, %rdi
callq 0x4050
movb %r12b, 0x2cc(%rbx)
movl %r15d, 0x298(%rbx)
andl $0x0, 0x294(%rbx)
movl %r15d, %edi
callq 0xdb33
movl %eax, 0x29c(%rbx)
cmpb $0x1, 0x2cc(%rbx)
jne 0x53c4
leaq 0xa03d(%rip), %rsi      # 0xf3c2
movq %rbx, %rdi
callq 0x4370
movq %rax, %rdi
callq 0x41d0
leaq 0xa03c(%rip), %rsi      # 0xf3d8
leaq -0xd8(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x4170
leaq -0xd8(%rbp), %rsi
movq %rbx, %rdi
callq 0x5624
leaq -0xd8(%rbp), %rdi
jmp 0x53f1
leaq 0xa019(%rip), %rsi      # 0xf3e4
leaq -0xb8(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x4170
leaq -0xb8(%rbp), %rsi
movq %rbx, %rdi
callq 0x5624
leaq -0xb8(%rbp), %rdi
callq 0x41b0
leaq 0x2a0(%rbx), %r15
movq %r15, %rdi
callq 0x8608
andl $0x0, 0x2c8(%rbx)
movq %r15, %rdi
callq 0x4290
movq %rbx, %rdi
callq 0x5816
leaq 0x4ad(%rip), %rax       # 0x58d0
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
andq $0x0, 0x8(%rsi)
leaq -0x38(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x48(%rbp), %rdi
callq 0x861e
leaq 0x6ee(%rip), %rax       # 0x5b34
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
andq $0x0, 0x8(%rsi)
leaq -0x40(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x38(%rbp), %rdi
callq 0x861e
leaq 0xbf1(%rip), %rax       # 0x605a
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
andq $0x0, 0x8(%rsi)
leaq -0x98(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x40(%rbp), %rdi
callq 0x861e
movq 0x338(%rbx), %rax
leaq -0x38(%rbp), %r14
movq (%r14), %rcx
movq %rcx, 0x338(%rbx)
movq %rax, (%r14)
movq 0x340(%rbx), %rax
leaq -0x40(%rbp), %rdi
movq (%rdi), %rcx
movq %rcx, 0x340(%rbx)
movq %rax, (%rdi)
movq 0x348(%rbx), %rax
leaq -0x48(%rbp), %r15
movq (%r15), %rcx
movq %rcx, 0x348(%rbx)
movq %rax, (%r15)
andw $0x0, 0x350(%rbx)
callq 0x5204
movq %r14, %rdi
callq 0x5204
movq %r15, %rdi
callq 0x5204
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, -0x30(%rbp)
leaq -0xd8(%rbp), %rdi
jmp 0x5519
jmp 0x5542
movq %rax, -0x30(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x41b0
jmp 0x5546
jmp 0x5542
movq %rax, -0x30(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5204
jmp 0x5535
movq %rax, -0x30(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5204
jmp 0x5546
jmp 0x5542
movq %rax, -0x30(%rbp)
leaq 0x200(%rbx), %rax
movq %rax, -0x90(%rbp)
leaq 0x270(%rbx), %rax
movq %rax, -0x88(%rbp)
leaq 0x2d8(%rbx), %rax
movq %rax, -0x70(%rbp)
leaq 0x2f8(%rbx), %rax
movq %rax, -0x68(%rbp)
leaq 0x338(%rbx), %rax
movq %rax, -0x60(%rbp)
leaq 0x340(%rbx), %r15
leaq 0x348(%rbx), %r13
leaq 0x358(%rbx), %r12
leaq 0x258(%rbx), %rax
movq %rax, -0x78(%rbp)
leaq 0x218(%rbx), %rax
movq %rax, -0x80(%rbp)
movq %r14, %rdi
callq 0x45f0
movq %r12, %rdi
callq 0x869c
movq %r13, %rdi
callq 0x5204
movq %r15, %rdi
callq 0x5204
movq -0x60(%rbp), %rdi
callq 0x5204
movq -0x68(%rbp), %rdi
callq 0x8a4a
movq -0x70(%rbp), %rdi
callq 0x41b0
movq -0x88(%rbp), %rdi
callq 0x41b0
movq -0x78(%rbp), %rdi
callq 0x86dc
movq -0x80(%rbp), %rdi
callq 0x86dc
movq -0x90(%rbp), %rdi
callq 0x8708
movq %rbx, %rdi
callq 0x4678
movq -0x30(%rbp), %rdi
callq 0x45d0