// File: vianna274[P]dropbox/src/Client.cpp
// Function: Dropbox::Client::Client(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Client::Client (string username, string serverAddr, int serverDistributorPort, string localIp) : username(username), syncDirPath("/tmp/sync_dir_"+username+"/")
{
	WrapperSocket socketToGetPort(serverAddr, serverDistributorPort);
	this->username = username;
	this->localIp = localIp;
	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_OFF);
	if(newPort->type == TYPE_MAKE_CONNECTION){
		this->socket = new WrapperSocket(serverAddr, stoi(newPort->payload));
	} 
	else if(newPort->type == TYPE_REJECT_TO_LISTEN) {
		cout << newPort->payload << endl;
		std::exit(1);
	}

	get_sync_dir();
	this->listenToMaster = new WrapperSocket(10000);
	thread listenToMasterThread(&Client::listenMaster, this);
	listenToMasterThread.detach();
	thread askServerUpdatesThread(&Client::askServerUpdates, this);
	askServerUpdatesThread.detach();
	cout << "Connected Successfully." << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x11d0, %rsp           # imm = 0x11D0
movq %rsi, -0x1138(%rbp)
movq %rdx, -0x1160(%rbp)
movq %r8, -0x1158(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x1140(%rbp)
movq %rdi, %rax
movq %rax, -0x1150(%rbp)
callq 0x9900
movq -0x1140(%rbp), %rdi
movq -0x1138(%rbp), %rsi
callq 0x3190
movq -0x1140(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0x1148(%rbp)
callq 0x3490
movq -0x1140(%rbp), %rax
movq -0x1138(%rbp), %rdx
addq $0x50, %rax
movq %rax, -0x1130(%rbp)
leaq 0x15651(%rip), %rsi     # 0x19038
leaq -0x48(%rbp), %rdi
callq 0x6780
jmp 0x39f2
movq -0x1130(%rbp), %rdi
leaq 0x15a07(%rip), %rdx     # 0x19407
leaq -0x48(%rbp), %rsi
callq 0x6730
jmp 0x3a0b
leaq -0x48(%rbp), %rdi
callq 0x3280
movq -0x1150(%rbp), %rdi
addq $0x70, %rdi
callq 0x6890
movq -0x1150(%rbp), %rdi
addq $0x98, %rdi
callq 0x6890
movq -0x1150(%rbp), %rdi
addq $0xc0, %rdi
movq %rdi, -0x1170(%rbp)
callq 0x68b0
movq -0x1150(%rbp), %rdi
addq $0xd8, %rdi
movq %rdi, -0x1168(%rbp)
callq 0x3490
movq -0x1160(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x3190
jmp 0x3a80
movl -0x1c(%rbp), %edx
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x17690
jmp 0x3a98
leaq -0xc0(%rbp), %rdi
callq 0x3280
movq -0x1150(%rbp), %rdi
movq -0x1138(%rbp), %rsi
callq 0x3060
jmp 0x3ab9
movq -0x1158(%rbp), %rsi
movq -0x1150(%rbp), %rdi
addq $0x20, %rdi
callq 0x3060
jmp 0x3ad2
movq -0x1150(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0x1188(%rbp)
callq 0x3510
movq -0x1188(%rbp), %rdi
movl %eax, -0x117c(%rbp)
callq 0x3180
movq -0x1150(%rbp), %rdi
movq %rax, -0x1178(%rbp)
callq 0x3180
movl -0x117c(%rbp), %r8d
movq -0x1178(%rbp), %r9
movq %rax, %rcx
movq %rsp, %rax
movq %rcx, (%rax)
leaq -0x1094(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %ecx
movl %ecx, %edx
callq 0x9830
jmp 0x3b3f
leaq -0xa0(%rbp), %rdi
leaq -0x1094(%rbp), %rsi
callq 0x17d90
jmp 0x3b54
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
callq 0x18090
movq %rax, -0x1190(%rbp)
jmp 0x3b6b
movq -0x1190(%rbp), %rax
movq %rax, -0x10a0(%rbp)
movq -0x10a0(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x3d45
movl $0x48, %edi
callq 0x33b0
movq %rax, -0x1198(%rbp)
jmp 0x3b9c
movq -0x1160(%rbp), %rsi
movb $0x1, -0x10e2(%rbp)
leaq -0x10c0(%rbp), %rdi
callq 0x3190
jmp 0x3bb8
movq -0x10a0(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x11a8(%rbp)
leaq -0x10e1(%rbp), %rdi
movq %rdi, -0x11a0(%rbp)
callq 0x3620
movq -0x11a8(%rbp), %rsi
movq -0x11a0(%rbp), %rdx
leaq -0x10e0(%rbp), %rdi
callq 0x3480
jmp 0x3bf9
xorl %eax, %eax
movl %eax, %esi
leaq -0x10e0(%rbp), %rdi
movl $0xa, %edx
callq 0x68d0
movl %eax, -0x11ac(%rbp)
jmp 0x3c16
movl -0x11ac(%rbp), %edx
movq -0x1198(%rbp), %rdi
leaq -0x10c0(%rbp), %rsi
callq 0x17690
jmp 0x3c31
movq -0x1150(%rbp), %rax
movq -0x1198(%rbp), %rcx
movb $0x0, -0x10e2(%rbp)
movq %rcx, 0x40(%rax)
leaq -0x10e0(%rbp), %rdi
callq 0x3280
leaq -0x10e1(%rbp), %rdi
callq 0x33e0
leaq -0x10c0(%rbp), %rdi
callq 0x3280
jmp 0x3d92
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3f4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x3280
jmp 0x3f4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3f29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x3280
jmp 0x3f29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3f1d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3d29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3d11
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x10e0(%rbp), %rdi
callq 0x3280
leaq -0x10e1(%rbp), %rdi
callq 0x33e0
leaq -0x10c0(%rbp), %rdi
callq 0x3280
testb $0x1, -0x10e2(%rbp)
jne 0x3d34
jmp 0x3d40
movq -0x1198(%rbp), %rdi
callq 0x3370
jmp 0x3f1d
movq -0x10a0(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x3d90
movq -0x10a0(%rbp), %rsi
addq $0x14, %rsi
movq 0x1f265(%rip), %rdi     # 0x22fc8
callq 0x33a0
movq %rax, -0x11b8(%rbp)
jmp 0x3d71
movq -0x11b8(%rbp), %rdi
movq 0x1f231(%rip), %rsi     # 0x22fb0
callq 0x33d0
jmp 0x3d86
movl $0x1, %edi
callq 0x3420
jmp 0x3d92
movq -0x1150(%rbp), %rdi
callq 0x3f70
jmp 0x3da0
movl $0x48, %edi
callq 0x33b0
movq %rax, -0x11c0(%rbp)
jmp 0x3db3
movq -0x11c0(%rbp), %rdi
movl $0x2710, %esi           # imm = 0x2710
callq 0x177a0
jmp 0x3dc6
movq -0x1150(%rbp), %rax
movq -0x11c0(%rbp), %rcx
movq %rcx, 0x48(%rax)
leaq 0x681(%rip), %rcx       # 0x4460
movq %rcx, -0x1100(%rbp)
movq $0x0, -0x10f8(%rbp)
movq %rax, -0x1108(%rbp)
leaq -0x10f0(%rbp), %rdi
leaq -0x1100(%rbp), %rsi
leaq -0x1108(%rbp), %rdx
callq 0x6910
jmp 0x3e14
leaq -0x10f0(%rbp), %rdi
callq 0x3600
jmp 0x3e22
movq -0x1150(%rbp), %rax
leaq 0xbc0(%rip), %rcx       # 0x49f0
movq %rcx, -0x1120(%rbp)
movq $0x0, -0x1118(%rbp)
movq %rax, -0x1128(%rbp)
leaq -0x1110(%rbp), %rdi
leaq -0x1120(%rbp), %rsi
leaq -0x1128(%rbp), %rdx
callq 0x6910
jmp 0x3e65
leaq -0x1110(%rbp), %rdi
callq 0x3600
jmp 0x3e73
movq 0x1f14e(%rip), %rdi     # 0x22fc8
leaq 0x151c6(%rip), %rsi     # 0x19047
callq 0x33a0
movq %rax, -0x11c8(%rbp)
jmp 0x3e8f
movq -0x11c8(%rbp), %rdi
movq 0x1f113(%rip), %rsi     # 0x22fb0
callq 0x33d0
jmp 0x3ea4
leaq -0x1110(%rbp), %rdi
callq 0x69d0
leaq -0x10f0(%rbp), %rdi
callq 0x69d0
leaq -0xa0(%rbp), %rdi
callq 0x17770
addq $0x11d0, %rsp           # imm = 0x11D0
popq %rbp
retq
movq -0x11c0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0x3370
jmp 0x3f1d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3f11
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1110(%rbp), %rdi
callq 0x69d0
leaq -0x10f0(%rbp), %rdi
callq 0x69d0
leaq -0xa0(%rbp), %rdi
callq 0x17770
movq -0x1168(%rbp), %rdi
callq 0x3280
movq -0x1170(%rbp), %rdi
callq 0x6a00
movq -0x1130(%rbp), %rdi
callq 0x3280
movq -0x1148(%rbp), %rdi
callq 0x3280
movq -0x1140(%rbp), %rdi
callq 0x3280
movq -0x50(%rbp), %rdi
callq 0x3610
nop