// File: luisremis[P]SDFS/Membership.cpp
// Function: Membership::newLeaderMsg(Message, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Membership::newLeaderMsg( Message msg, std::string sender )
{
	logFile << "New leader recieved... lets check that..." << std::endl;
	bool flag = false;
	if ( isBiggerThanMine(sender, my_ip_str) )
	{
		membersLock.lock();

		for (int i = 0; i < members.size(); ++i)
		{
			if ( 0 == sender.compare(members.at(i).ip_str) )
			{
				logFile<< "Ok, new leader acepted: " <<  sender << std::endl;
				leader = members.at(i);
				leader.active = true;
				flag = true;
			}
			// Message msg;
			// msg.type = MSG_NEWLEADER_ACK;
			// sendUDP( sockfd,  other, port, (char*)&msg, sizeof(Message) );
		}

		membersLock.unlock();

		if(!flag)
		{
			runLeaderElection();
		}
	}
	else
	{
		logFile << "I am bigger than that guy! Re runnig election" <<  sender << std::endl;
		runLeaderElection();
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rsi, -0x78(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
leaq 0x1272b(%rip), %rsi     # 0x1c8b1
callq 0x43f0
movq %rax, %rdi
movq 0x1ce13(%rip), %rsi     # 0x26fa8
callq 0x4410
movq -0x78(%rbp), %rsi
movb $0x0, -0x11(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x41e0
movq -0x70(%rbp), %rsi
addq $0x2d8, %rsi            # imm = 0x2D8
leaq -0x58(%rbp), %rdi
callq 0x41e0
jmp 0xa1c1
movq -0x70(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0xa860
movb %al, -0x79(%rbp)
jmp 0xa1d7
leaq -0x58(%rbp), %rdi
callq 0x42a0
leaq -0x38(%rbp), %rdi
callq 0x42a0
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0xa1f5
jmp 0xa32b
movq -0x70(%rbp), %rdi
addq $0x230, %rdi            # imm = 0x230
callq 0xb5f0
movl $0x0, -0x68(%rbp)
movq -0x70(%rbp), %rdi
movslq -0x68(%rbp), %rax
movq %rax, -0x88(%rbp)
addq $0x258, %rdi            # imm = 0x258
callq 0xb990
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq %rcx, %rax
jae 0xa30a
movq -0x70(%rbp), %rdi
addq $0x258, %rdi            # imm = 0x258
movslq -0x68(%rbp), %rsi
callq 0xb950
movq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x4040
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xa2fa
movq -0x70(%rbp), %rdi
leaq 0x1266a(%rip), %rsi     # 0x1c8db
callq 0x43f0
movq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0x4370
movq %rax, %rdi
movq 0x1cd1c(%rip), %rsi     # 0x26fa8
callq 0x4410
movq -0x70(%rbp), %rdi
addq $0x258, %rdi            # imm = 0x258
movslq -0x68(%rbp), %rsi
callq 0xb950
movq -0x70(%rbp), %rdi
movq %rax, %rsi
addq $0x270, %rdi            # imm = 0x270
callq 0xbbd0
movq -0x70(%rbp), %rax
movl $0x1, 0x294(%rax)
movb $0x1, -0x11(%rbp)
jmp 0xa2fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0xa2ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x42a0
leaq -0x38(%rbp), %rdi
callq 0x42a0
jmp 0xa368
jmp 0xa2fc
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0xa20c
movq -0x70(%rbp), %rdi
addq $0x230, %rdi            # imm = 0x230
callq 0xb620
testb $0x1, -0x11(%rbp)
jne 0xa329
movq -0x70(%rbp), %rdi
callq 0xabb0
jmp 0xa35f
movq -0x70(%rbp), %rdi
leaq 0x125be(%rip), %rsi     # 0x1c8f4
callq 0x43f0
movq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0x4370
movq %rax, %rdi
movq 0x1cc57(%rip), %rsi     # 0x26fa8
callq 0x4410
movq -0x70(%rbp), %rdi
callq 0xabb0
addq $0x90, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x46a0
nopw %cs:(%rax,%rax)