// File: vianna274[P]dropbox/src/Client.cpp
// Function: Dropbox::Client::listenMaster()
void Client::listenMaster() {
	while(1) {
		MessageData * data = this->listenToMaster->receive(TIMEOUT_OFF);
		if (data->type == TYPE_NEW_BOSS) {
			
			while(1) {
				WrapperSocket socketToGetPort(string(data->payload), 4000);
				MessageData request = make_packet(TYPE_MAKE_CONNECTION, 1, 1, this->localIp.length(), this->localIp.c_str(), this->username.c_str());
				socketToGetPort.send(&request);
				MessageData *newPort = socketToGetPort.receive(TIMEOUT_ON, 1500);
				if(newPort != NULL && newPort->type == TYPE_MAKE_CONNECTION){
				
					socketMtx.lock();
					this->socket = new WrapperSocket(string(data->payload), stoi(newPort->payload));
					this->payload1 = string(data->payload);
					this->payload2 = stoi(newPort->payload);
					socketMtx.unlock();
					break;
				} 
				else if(newPort != NULL && newPort->type == TYPE_REJECT_TO_LISTEN) {
					cout << newPort->payload << endl;
					std::exit(1);
				}
			}
			
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x11b0, %rsp           # imm = 0x11B0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1110(%rbp)
movq -0x1110(%rbp), %rax
movq 0x48(%rax), %rdi
xorl %esi, %esi
callq 0x18090
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x13, (%rax)
jne 0x49de
jmp 0x449f
movq -0x10(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x1120(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x1118(%rbp)
callq 0x3620
movq -0x1120(%rbp), %rsi
movq -0x1118(%rbp), %rdx
leaq -0x78(%rbp), %rdi
callq 0x3480
jmp 0x44d7
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0xfa0, %edx            # imm = 0xFA0
callq 0x17690
jmp 0x44eb
leaq -0x78(%rbp), %rdi
callq 0x3280
leaq -0x79(%rbp), %rdi
callq 0x33e0
movq -0x1110(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0x1138(%rbp)
callq 0x3510
movq -0x1138(%rbp), %rdi
movl %eax, -0x112c(%rbp)
callq 0x3180
movq -0x1110(%rbp), %rdi
movq %rax, -0x1128(%rbp)
callq 0x3180
movl -0x112c(%rbp), %r8d
movq -0x1128(%rbp), %r9
movq %rax, %rcx
movq %rsp, %rax
movq %rcx, (%rax)
leaq -0x1060(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %ecx
movl %ecx, %edx
callq 0x9830
jmp 0x456a
leaq -0x58(%rbp), %rdi
leaq -0x1060(%rbp), %rsi
callq 0x17d90
jmp 0x457c
leaq -0x58(%rbp), %rdi
movl $0x1, %esi
movl $0x5dc, %edx            # imm = 0x5DC
callq 0x17bc0
movq %rax, -0x1140(%rbp)
jmp 0x4598
movq -0x1140(%rbp), %rax
movq %rax, -0x1068(%rbp)
cmpq $0x0, -0x1068(%rbp)
je 0x4954
movq -0x1068(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x4954
movq -0x1110(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a60
jmp 0x45d9
movl $0x48, %edi
callq 0x33b0
movq %rax, -0x1148(%rbp)
jmp 0x45ec
movb $0x1, -0x10b2(%rbp)
movq -0x10(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x1158(%rbp)
leaq -0x1089(%rbp), %rdi
movq %rdi, -0x1150(%rbp)
callq 0x3620
movq -0x1158(%rbp), %rsi
movq -0x1150(%rbp), %rdx
leaq -0x1088(%rbp), %rdi
callq 0x3480
jmp 0x4631
movq -0x1068(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x1168(%rbp)
leaq -0x10b1(%rbp), %rdi
movq %rdi, -0x1160(%rbp)
callq 0x3620
movq -0x1168(%rbp), %rsi
movq -0x1160(%rbp), %rdx
leaq -0x10b0(%rbp), %rdi
callq 0x3480
jmp 0x4672
xorl %eax, %eax
movl %eax, %esi
leaq -0x10b0(%rbp), %rdi
movl $0xa, %edx
callq 0x68d0
movl %eax, -0x116c(%rbp)
jmp 0x468f
movl -0x116c(%rbp), %edx
movq -0x1148(%rbp), %rdi
leaq -0x1088(%rbp), %rsi
callq 0x17690
jmp 0x46aa
movq -0x1110(%rbp), %rax
movq -0x1148(%rbp), %rcx
movb $0x0, -0x10b2(%rbp)
movq %rcx, 0x40(%rax)
leaq -0x10b0(%rbp), %rdi
callq 0x3280
leaq -0x10b1(%rbp), %rdi
callq 0x33e0
leaq -0x1088(%rbp), %rdi
callq 0x3280
leaq -0x1089(%rbp), %rdi
callq 0x33e0
movq -0x10(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x1180(%rbp)
leaq -0x10d9(%rbp), %rdi
movq %rdi, -0x1178(%rbp)
callq 0x3620
movq -0x1180(%rbp), %rsi
movq -0x1178(%rbp), %rdx
leaq -0x10d8(%rbp), %rdi
callq 0x3480
jmp 0x4731
movq -0x1110(%rbp), %rdi
addq $0xd8, %rdi
leaq -0x10d8(%rbp), %rsi
movq %rsi, -0x1198(%rbp)
callq 0x3430
movq -0x1198(%rbp), %rdi
callq 0x3280
leaq -0x10d9(%rbp), %rdi
callq 0x33e0
movq -0x1068(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x1190(%rbp)
leaq -0x1101(%rbp), %rdi
movq %rdi, -0x1188(%rbp)
callq 0x3620
movq -0x1190(%rbp), %rsi
movq -0x1188(%rbp), %rdx
leaq -0x1100(%rbp), %rdi
callq 0x3480
jmp 0x47ab
xorl %eax, %eax
movl %eax, %esi
leaq -0x1100(%rbp), %rdi
movl $0xa, %edx
callq 0x68d0
movl %eax, -0x119c(%rbp)
jmp 0x47c8
movq -0x1110(%rbp), %rax
movl -0x119c(%rbp), %ecx
movl %ecx, 0xf8(%rax)
leaq -0x1100(%rbp), %rdi
callq 0x3280
leaq -0x1101(%rbp), %rdi
callq 0x33e0
movq -0x1110(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a90
jmp 0x4808
movl $0x5, -0x1108(%rbp)
jmp 0x49b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x4846
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3280
leaq -0x79(%rbp), %rdi
callq 0x33e0
jmp 0x49e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x49d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x48c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x48b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x10b0(%rbp), %rdi
callq 0x3280
leaq -0x10b1(%rbp), %rdi
callq 0x33e0
leaq -0x1088(%rbp), %rdi
callq 0x3280
leaq -0x1089(%rbp), %rdi
callq 0x33e0
testb $0x1, -0x10b2(%rbp)
jne 0x48e0
jmp 0x48ec
movq -0x1148(%rbp), %rdi
callq 0x3370
jmp 0x49d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x10d9(%rbp), %rdi
callq 0x33e0
jmp 0x49d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x4946
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x1100(%rbp), %rdi
callq 0x3280
leaq -0x1101(%rbp), %rdi
callq 0x33e0
jmp 0x49d1
cmpq $0x0, -0x1068(%rbp)
je 0x49a9
movq -0x1068(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x49a9
movq -0x1068(%rbp), %rsi
addq $0x14, %rsi
movq 0x1e64c(%rip), %rdi     # 0x22fc8
callq 0x33a0
movq %rax, -0x11a8(%rbp)
jmp 0x498a
movq -0x11a8(%rbp), %rdi
movq 0x1e618(%rip), %rsi     # 0x22fb0
callq 0x33d0
jmp 0x499f
movl $0x1, %edi
callq 0x3420
jmp 0x49ab
movl $0x0, -0x1108(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x17770
movl -0x1108(%rbp), %eax
testl %eax, %eax
je 0x49cc
jmp 0x49ca
jmp 0x49dc
jmp 0x449f
leaq -0x58(%rbp), %rdi
callq 0x17770
jmp 0x49e3
jmp 0x49de
jmp 0x447a
movq -0x88(%rbp), %rdi
callq 0x3610
nop