// File: vianna274[P]dropbox/src/Client.cpp
// Function: Dropbox::Client::askUpdate()
void Client::askUpdate() {
	MessageData request = make_packet(TYPE_REQUEST_UPDATE, 1 , 1, -1, "type_request_update", this->username.c_str());
	socketMtx.lock();
	bool ass = this->socket->send(&request);
	socketMtx.unlock();
	if (ass == -1) {
		socketMtx.lock();
		this->socket = new WrapperSocket(this->payload1, this->payload2);
		socketMtx.unlock();
		ass = this->socket->send(&request);
	}
	else if (ass == 0)
		return;
	this->sendFileList(this->socket, this->fileRecords);
	while(1) {
		socketMtx.lock();
		MessageData * response = this->socket->receive(TIMEOUT_ON);
		socketMtx.unlock();
		FileRecord fileRecord;
		if (response == NULL) return;
		switch (response->type) {
			case TYPE_NOTHING_TO_SEND:
				break;
			case TYPE_REQUEST_UPDATE_DONE:
				return;
			case TYPE_DELETE:
				socketMtx.lock();
				this->deleteFile(this->getSyncDirPath() + string(response->payload));
				socketMtx.unlock();
				this->removeFileRecord(string(response->payload));
				break;
			case TYPE_SEND_FILE:
				fileRecord = *((FileRecord *)response->payload);
				socketMtx.lock();
				this->receiveFile(this->socket, string(fileRecord.filename), 
					this->getSyncDirPath());
				socketMtx.unlock();
				this->updateFileRecord(fileRecord);
				break;
			case TYPE_SEND_UPLOAD_ALL:
				socketMtx.lock();
				this->receiveUploadAll(this->socket, this->getSyncDirPath());
				socketMtx.unlock();
				break;
			case TYPE_DELETE_ALL:
				socketMtx.lock();
				this->deleteAll(this->getFileList(this->getSyncDirPath()), this->getSyncDirPath());
				socketMtx.unlock();
				break;
			default:
				cout << "Received " + to_string(response->type) << endl;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1500, %rsp           # imm = 0x1500
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x1398(%rbp)
callq 0x3180
leaq -0xfdc(%rbp), %rdi
movl $0xe, %esi
movl $0x1, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
leaq 0x13c4a(%rip), %r9      # 0x190a7
movl %ecx, %edx
movq %rax, (%rsp)
callq 0x9830
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a60
movq -0x1398(%rbp), %rax
movq 0x40(%rax), %rdi
leaq -0xfdc(%rbp), %rsi
callq 0x17d90
movq -0x1398(%rbp), %rdi
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0xfdd(%rbp)
addq $0x98, %rdi
callq 0x6a90
movb -0xfdd(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $-0x1, %eax
jne 0x55dd
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a60
movl $0x48, %edi
callq 0x33b0
movq -0x1398(%rbp), %rsi
movq %rax, -0x13a0(%rbp)
movb $0x1, -0x100d(%rbp)
addq $0xd8, %rsi
leaq -0x1000(%rbp), %rdi
callq 0x3190
jmp 0x550e
movq -0x13a0(%rbp), %rdi
movq -0x1398(%rbp), %rax
movl 0xf8(%rax), %edx
leaq -0x1000(%rbp), %rsi
callq 0x17690
jmp 0x5530
movq -0x1398(%rbp), %rax
movq -0x13a0(%rbp), %rcx
movb $0x0, -0x100d(%rbp)
movq %rcx, 0x40(%rax)
leaq -0x1000(%rbp), %rdi
callq 0x3280
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a90
movq -0x1398(%rbp), %rax
movq 0x40(%rax), %rdi
leaq -0xfdc(%rbp), %rsi
callq 0x17d90
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0xfdd(%rbp)
jmp 0x55f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
jmp 0x55c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
leaq -0x1000(%rbp), %rdi
callq 0x3280
testb $0x1, -0x100d(%rbp)
jne 0x55cc
jmp 0x55d8
movq -0x13a0(%rbp), %rdi
callq 0x3370
jmp 0x5d02
movb -0xfdd(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x55f2
jmp 0x5cf9
jmp 0x55f4
movq -0x1398(%rbp), %rsi
movq 0x40(%rsi), %rax
movq %rax, -0x13b0(%rbp)
addq $0xc0, %rsi
leaq -0x1028(%rbp), %rdi
movq %rdi, -0x13a8(%rbp)
callq 0x6bc0
movq -0x1398(%rbp), %rdi
movq -0x13b0(%rbp), %rsi
movq -0x13a8(%rbp), %rdx
callq 0x9ac0
jmp 0x563c
leaq -0x1028(%rbp), %rdi
callq 0x6a00
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a60
movq -0x1398(%rbp), %rax
movq 0x40(%rax), %rdi
movl $0x1, %esi
callq 0x18090
movq -0x1398(%rbp), %rdi
movq %rax, -0x1030(%rbp)
addq $0x98, %rdi
callq 0x6a90
cmpq $0x0, -0x1030(%rbp)
jne 0x56bc
jmp 0x5cf9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
leaq -0x1028(%rbp), %rdi
callq 0x6a00
jmp 0x5d02
movq -0x1030(%rbp), %rax
movl (%rax), %eax
addl $-0x3, %eax
movl %eax, %ecx
movq %rcx, -0x13b8(%rbp)
subl $0xc, %eax
ja 0x5c33
movq -0x13b8(%rbp), %rax
leaq 0x1391c(%rip), %rcx     # 0x19004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x5cb4
jmp 0x5cf9
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a60
movq -0x1398(%rbp), %rsi
leaq -0x1158(%rbp), %rdi
callq 0x6d80
movq -0x1030(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x13c8(%rbp)
leaq -0x1179(%rbp), %rdi
movq %rdi, -0x13c0(%rbp)
callq 0x3620
movq -0x13c8(%rbp), %rsi
movq -0x13c0(%rbp), %rdx
leaq -0x1178(%rbp), %rdi
callq 0x3480
jmp 0x5762
leaq -0x1138(%rbp), %rdi
leaq -0x1158(%rbp), %rsi
leaq -0x1178(%rbp), %rdx
callq 0x6cb0
jmp 0x577e
movq -0x1398(%rbp), %rdi
leaq -0x1138(%rbp), %rsi
callq 0xba10
jmp 0x5793
leaq -0x1138(%rbp), %rdi
callq 0x3280
leaq -0x1178(%rbp), %rdi
callq 0x3280
leaq -0x1179(%rbp), %rdi
callq 0x33e0
leaq -0x1158(%rbp), %rdi
callq 0x3280
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a90
movq -0x1030(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x13d8(%rbp)
leaq -0x11a1(%rbp), %rdi
movq %rdi, -0x13d0(%rbp)
callq 0x3620
movq -0x13d8(%rbp), %rsi
movq -0x13d0(%rbp), %rdx
leaq -0x11a0(%rbp), %rdi
callq 0x3480
jmp 0x5817
movq -0x1398(%rbp), %rdi
leaq -0x11a0(%rbp), %rsi
callq 0x5e90
jmp 0x582c
leaq -0x11a0(%rbp), %rdi
callq 0x3280
leaq -0x11a1(%rbp), %rdi
callq 0x33e0
jmp 0x5cb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
jmp 0x589b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
jmp 0x588f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
leaq -0x1138(%rbp), %rdi
callq 0x3280
leaq -0x1178(%rbp), %rdi
callq 0x3280
leaq -0x1179(%rbp), %rdi
callq 0x33e0
leaq -0x1158(%rbp), %rdi
callq 0x3280
jmp 0x5d02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
jmp 0x58ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
leaq -0x11a0(%rbp), %rdi
callq 0x3280
leaq -0x11a1(%rbp), %rdi
callq 0x33e0
jmp 0x5d02
movq -0x1030(%rbp), %rsi
addq $0x14, %rsi
leaq -0x1118(%rbp), %rdi
movq %rdi, -0x13e8(%rbp)
movl $0xe8, %edx
callq 0x3300
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a60
movq -0x1398(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x13f0(%rbp)
leaq -0x11c9(%rbp), %rdi
movq %rdi, -0x13e0(%rbp)
callq 0x3620
movq -0x13e8(%rbp), %rsi
movq -0x13e0(%rbp), %rdx
leaq -0x11c8(%rbp), %rdi
callq 0x3480
jmp 0x5972
movq -0x1398(%rbp), %rsi
leaq -0x11f0(%rbp), %rdi
callq 0x6d80
jmp 0x5987
movq -0x13f0(%rbp), %rsi
movq -0x1398(%rbp), %rdi
leaq -0x11c8(%rbp), %rdx
leaq -0x11f0(%rbp), %rcx
callq 0x9c30
jmp 0x59aa
leaq -0x11f0(%rbp), %rdi
callq 0x3280
leaq -0x11c8(%rbp), %rdi
callq 0x3280
leaq -0x11c9(%rbp), %rdi
callq 0x33e0
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a90
leaq -0x12d8(%rbp), %rdi
leaq -0x1118(%rbp), %rsi
movl $0xe8, %edx
callq 0x3300
movq %rsp, %rdi
movl $0x1d, %ecx
leaq -0x12d8(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x1398(%rbp), %rdi
callq 0x5ff0
jmp 0x5cb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
jmp 0x5a6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
jmp 0x5a62
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
leaq -0x11f0(%rbp), %rdi
callq 0x3280
leaq -0x11c8(%rbp), %rdi
callq 0x3280
leaq -0x11c9(%rbp), %rdi
callq 0x33e0
jmp 0x5d02
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a60
movq -0x1398(%rbp), %rsi
movq 0x40(%rsi), %rax
movq %rax, -0x1400(%rbp)
leaq -0x12f8(%rbp), %rdi
movq %rdi, -0x13f8(%rbp)
callq 0x6d80
movq -0x1398(%rbp), %rdi
movq -0x1400(%rbp), %rsi
movq -0x13f8(%rbp), %rdx
callq 0xb480
jmp 0x5ad3
leaq -0x12f8(%rbp), %rdi
callq 0x3280
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a90
jmp 0x5cb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
leaq -0x12f8(%rbp), %rdi
callq 0x3280
jmp 0x5d02
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a60
movq -0x1398(%rbp), %rsi
leaq -0x1330(%rbp), %rdi
movq %rdi, -0x1408(%rbp)
callq 0x6d80
movq -0x1398(%rbp), %rsi
movq -0x1408(%rbp), %rdx
leaq -0x1310(%rbp), %rdi
callq 0x9910
jmp 0x5b63
movq -0x1398(%rbp), %rsi
leaq -0x1350(%rbp), %rdi
callq 0x6d80
jmp 0x5b78
movq -0x1398(%rbp), %rdi
leaq -0x1310(%rbp), %rsi
leaq -0x1350(%rbp), %rdx
callq 0xba70
jmp 0x5b94
leaq -0x1350(%rbp), %rdi
callq 0x3280
leaq -0x1310(%rbp), %rdi
callq 0x6a00
leaq -0x1330(%rbp), %rdi
callq 0x3280
movq -0x1398(%rbp), %rdi
addq $0x98, %rdi
callq 0x6a90
jmp 0x5cb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
jmp 0x5c22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
jmp 0x5c16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
leaq -0x1350(%rbp), %rdi
callq 0x3280
leaq -0x1310(%rbp), %rdi
callq 0x6a00
leaq -0x1330(%rbp), %rdi
callq 0x3280
jmp 0x5d02
movq -0x1030(%rbp), %rax
movl (%rax), %esi
leaq -0x1390(%rbp), %rdi
movq %rdi, -0x1410(%rbp)
callq 0x6e00
movq -0x1410(%rbp), %rdx
leaq 0x1345e(%rip), %rsi     # 0x190bb
leaq -0x1370(%rbp), %rdi
callq 0x6db0
jmp 0x5c6b
movq 0x1d356(%rip), %rdi     # 0x22fc8
leaq -0x1370(%rbp), %rsi
callq 0x3330
movq %rax, -0x1418(%rbp)
jmp 0x5c87
movq -0x1418(%rbp), %rdi
movq 0x1d31b(%rip), %rsi     # 0x22fb0
callq 0x33d0
jmp 0x5c9c
leaq -0x1370(%rbp), %rdi
callq 0x3280
leaq -0x1390(%rbp), %rdi
callq 0x3280
jmp 0x5648
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
jmp 0x5ceb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1008(%rbp)
movl %eax, -0x100c(%rbp)
leaq -0x1370(%rbp), %rdi
callq 0x3280
leaq -0x1390(%rbp), %rdi
callq 0x3280
jmp 0x5d02
addq $0x1500, %rsp           # imm = 0x1500
popq %rbp
retq
movq -0x1008(%rbp), %rdi
callq 0x3610
nop