// File: luisremis[P]SDFS/Membership.cpp
// Function: Membership::failMsg(Message, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Membership::failMsg( Message msg, std::string sender )
{
	std::string carrier = char42String(msg.carrierAdd);
/*
    if ( my_ip_str.compare(carrier) == 0) // THIS IS MY! I NEED TO REJOIN
    {
        std::cout <<"they are trying to kill me!" << std::endl;
        membersLock.lock();
        members.clear();
        membersLock.unlock();
        usleep( 2000*1000 ); // wait 2 second and rejoin
        bool joined = firstJoin();
        while( !isIntroducer && !joined)
        {   //introducer will firstJoin() once. Other node will keep firstJoin() until it enter the group.
            joined = firstJoin();
            usleep( 1000*1000 );
        }
        return;
    }
*/
    failMember(carrier, msg.timeStamp);
	logFile<<"failMsg: node "<<carrier<<" failed acording to " << sender << std::endl;
/*
    int select = rand()%10;

    if (select <= 7) // 1 and 2
    //if (true) // 1 and 2
    {
        Message justInCase;
        justInCase.type = MSG_FAIL;
        msg.TTL = 0;
        ipString2Char4(carrier, justInCase.carrierAdd);
        sendUDP( sockfd,  carrier, port, (char*)&justInCase, sizeof(Message) );
        // Just in case let the node know so it can rejoin
    }
*/
    if(msg.TTL==0)
    {
        return;
    }
    else{
    	msg.TTL--;
    	spreadMessage(msg);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rsi, %rax
movq %rax, -0xa0(%rbp)
leaq 0x10(%rbp), %rsi
movq %rsi, -0x98(%rbp)
movq %rdi, -0x8(%rbp)
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
addq $0x5, %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x1a480
movq -0x88(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x41e0
jmp 0x9cc9
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rax
movl 0xc(%rax), %edx
leaq -0x50(%rbp), %rsi
callq 0x8f40
jmp 0x9ce5
leaq -0x50(%rbp), %rdi
callq 0x42a0
movq -0x90(%rbp), %rdi
leaq 0x12a71(%rip), %rsi     # 0x1c76d
callq 0x43f0
movq %rax, -0xa8(%rbp)
jmp 0x9d0a
movq -0xa8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4370
movq %rax, -0xb0(%rbp)
jmp 0x9d23
movq -0xb0(%rbp), %rdi
leaq 0x12a4b(%rip), %rsi     # 0x1c77c
callq 0x43f0
movq %rax, -0xb8(%rbp)
jmp 0x9d3f
movq -0xa0(%rbp), %rsi
movq -0xb8(%rbp), %rdi
callq 0x4370
movq %rax, -0xc0(%rbp)
jmp 0x9d5b
movq -0xc0(%rbp), %rdi
movq 0x1d23f(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x9d70
movq -0x98(%rbp), %rax
movsbl 0x10(%rax), %eax
cmpl $0x0, %eax
jne 0x9dae
movl $0x1, -0x60(%rbp)
jmp 0x9df3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x9e05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x42a0
jmp 0x9e05
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rax
movb 0x10(%rax), %cl
decb %cl
movb %cl, 0x10(%rax)
movl 0x10(%rax), %ecx
movl %ecx, -0x70(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0x80(%rbp)
movl -0x70(%rbp), %ecx
movq %rsp, %rax
movl %ecx, 0x10(%rax)
movaps -0x80(%rbp), %xmm0
movups %xmm0, (%rax)
xorl %esi, %esi
callq 0x8a90
jmp 0x9dea
jmp 0x9dec
movl $0x0, -0x60(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x42a0
addq $0xe0, %rsp
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x42a0
movq -0x58(%rbp), %rdi
callq 0x46a0
nopw (%rax,%rax)