Progress
This commit is contained in:
+22
-18
@@ -782,7 +782,7 @@ start_connecting_to_metadata_server(ChunkServer *state)
|
|||||||
Time current_time = get_current_time();
|
Time current_time = get_current_time();
|
||||||
|
|
||||||
ByteQueue *output;
|
ByteQueue *output;
|
||||||
if (tcp_connect(&state->tcp, state->metadata_server_addr, TAG_METADATA_SERVER, &output) < 0) {
|
if (tcp_connect(&state->tcp, state->remote_addr, TAG_METADATA_SERVER, &output) < 0) {
|
||||||
state->disconnect_time = current_time;
|
state->disconnect_time = current_time;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -797,17 +797,8 @@ start_connecting_to_metadata_server(ChunkServer *state)
|
|||||||
message_write(&writer, &num_ipv4, sizeof(num_ipv4));
|
message_write(&writer, &num_ipv4, sizeof(num_ipv4));
|
||||||
|
|
||||||
// Write our IPv4 address and port
|
// Write our IPv4 address and port
|
||||||
IPv4 our_ipv4;
|
message_write(&writer, &state->local_addr.ipv4, sizeof(state->local_addr.ipv4));
|
||||||
if (inet_pton(AF_INET, "127.0.0.1", &our_ipv4) == 1) {
|
message_write(&writer, &state->local_addr.port, sizeof(state->local_addr.port));
|
||||||
message_write(&writer, &our_ipv4, sizeof(our_ipv4));
|
|
||||||
uint16_t our_port = 8080; // From program_init
|
|
||||||
message_write(&writer, &our_port, sizeof(our_port));
|
|
||||||
} else {
|
|
||||||
// Failed to parse our address, send 0 IPv4s
|
|
||||||
num_ipv4 = 0;
|
|
||||||
// We already wrote 1, this is an error case
|
|
||||||
// For now, continue with the bad data
|
|
||||||
}
|
|
||||||
|
|
||||||
// No IPv6 addresses for now
|
// No IPv6 addresses for now
|
||||||
uint32_t num_ipv6 = 0;
|
uint32_t num_ipv6 = 0;
|
||||||
@@ -852,22 +843,35 @@ int chunk_server_init(ChunkServer *state, int argc, char **argv, void **contexts
|
|||||||
pending_download_list_init(&state->pending_download_list);
|
pending_download_list_init(&state->pending_download_list);
|
||||||
|
|
||||||
char tmp[1<<10];
|
char tmp[1<<10];
|
||||||
|
if (addr.len >= (int) sizeof(tmp)) {
|
||||||
|
tcp_context_free(&state->tcp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memcpy(tmp, addr.ptr, addr.len);
|
||||||
|
tmp[addr.len] = '\0';
|
||||||
|
state->local_addr.is_ipv4 = true;
|
||||||
|
if (inet_pton(AF_INET, tmp, &state->local_addr.ipv4) != 1) {
|
||||||
|
tcp_context_free(&state->tcp);
|
||||||
|
chunk_store_free(&state->store);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
state->local_addr.port = port;
|
||||||
|
|
||||||
|
// Initialize metadata server address
|
||||||
|
// // TODO: This should also support IPv6
|
||||||
if (remote_addr.len >= (int) sizeof(tmp)) {
|
if (remote_addr.len >= (int) sizeof(tmp)) {
|
||||||
tcp_context_free(&state->tcp);
|
tcp_context_free(&state->tcp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(tmp, remote_addr.ptr, remote_addr.len);
|
memcpy(tmp, remote_addr.ptr, remote_addr.len);
|
||||||
tmp[remote_addr.len] = '\0';
|
tmp[remote_addr.len] = '\0';
|
||||||
|
state->remote_addr.is_ipv4 = true;
|
||||||
// Initialize metadata server address
|
if (inet_pton(AF_INET, tmp, &state->remote_addr.ipv4) != 1) {
|
||||||
// // TODO: This should also support IPv6
|
|
||||||
state->metadata_server_addr.is_ipv4 = true;
|
|
||||||
if (inet_pton(AF_INET, tmp, &state->metadata_server_addr.ipv4) != 1) {
|
|
||||||
tcp_context_free(&state->tcp);
|
tcp_context_free(&state->tcp);
|
||||||
chunk_store_free(&state->store);
|
chunk_store_free(&state->store);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
state->metadata_server_addr.port = remote_port;
|
state->remote_addr.port = remote_port;
|
||||||
state->disconnect_time = INVALID_TIME;
|
state->disconnect_time = INVALID_TIME;
|
||||||
|
|
||||||
start_connecting_to_metadata_server(state);
|
start_connecting_to_metadata_server(state);
|
||||||
|
|||||||
+2
-2
@@ -26,11 +26,11 @@ typedef struct {
|
|||||||
} PendingDownloadList;
|
} PendingDownloadList;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Address metadata_server_addr;
|
Address local_addr;
|
||||||
|
Address remote_addr;
|
||||||
Time disconnect_time;
|
Time disconnect_time;
|
||||||
TCP tcp;
|
TCP tcp;
|
||||||
ChunkStore store;
|
ChunkStore store;
|
||||||
|
|
||||||
bool downloading;
|
bool downloading;
|
||||||
PendingDownloadList pending_download_list;
|
PendingDownloadList pending_download_list;
|
||||||
} ChunkServer;
|
} ChunkServer;
|
||||||
|
|||||||
+14
-2
@@ -1341,7 +1341,13 @@ static void process_event_for_write(TinyDFS *tdfs,
|
|||||||
tdfs->operations[opidx].result = (TinyDFS_Result) { .type=TINYDFS_RESULT_WRITE_ERROR };
|
tdfs->operations[opidx].result = (TinyDFS_Result) { .type=TINYDFS_RESULT_WRITE_ERROR };
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#if 1
|
||||||
|
{
|
||||||
|
char ip_str[INET_ADDRSTRLEN];
|
||||||
|
inet_ntop(AF_INET, &ipv4, ip_str, sizeof(ip_str));
|
||||||
|
printf("write location %s:%d\n", ip_str, port);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
int old_relative_off = relative_off;
|
int old_relative_off = relative_off;
|
||||||
|
|
||||||
for (int w = 0; w < num_new_hashes; w++) {
|
for (int w = 0; w < num_new_hashes; w++) {
|
||||||
@@ -1398,7 +1404,13 @@ static void process_event_for_write(TinyDFS *tdfs,
|
|||||||
tdfs->operations[opidx].result = (TinyDFS_Result) { .type=TINYDFS_RESULT_WRITE_ERROR };
|
tdfs->operations[opidx].result = (TinyDFS_Result) { .type=TINYDFS_RESULT_WRITE_ERROR };
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#if 1
|
||||||
|
{
|
||||||
|
char ip_str[INET_ADDRSTRLEN];
|
||||||
|
inet_ntop(AF_INET6, &ipv6, ip_str, sizeof(ip_str));
|
||||||
|
printf("write location %s:%d\n", ip_str, port);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
int old_relative_off = relative_off;
|
int old_relative_off = relative_off;
|
||||||
|
|
||||||
for (int w = 0; w < num_new_hashes; w++) {
|
for (int w = 0; w < num_new_hashes; w++) {
|
||||||
|
|||||||
@@ -252,8 +252,7 @@ int simulation_client_step(SimulationClient *client, void **contexts,
|
|||||||
*timeout = -1;
|
*timeout = -1;
|
||||||
} else {
|
} else {
|
||||||
// Wake up soon to continue processing
|
// Wake up soon to continue processing
|
||||||
//*timeout = 10; // 10ms
|
*timeout = 10; // 10ms
|
||||||
*timeout = -1; // TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the poll array from the TinyDFS client
|
// Return the poll array from the TinyDFS client
|
||||||
|
|||||||
+12
-2
@@ -652,7 +652,7 @@ void update_simulation(void)
|
|||||||
num_polled = chunk_server_step(¤t_process->chunk_server, contexts, polled, num_polled, &timeout);
|
num_polled = chunk_server_step(¤t_process->chunk_server, contexts, polled, num_polled, &timeout);
|
||||||
break;
|
break;
|
||||||
case PROCESS_TYPE_CLIENT:
|
case PROCESS_TYPE_CLIENT:
|
||||||
printf("simulation_client_step\n");
|
//printf("simulation_client_step\n");
|
||||||
num_polled = simulation_client_step(¤t_process->simulation_client, contexts, polled, num_polled, &timeout);
|
num_polled = simulation_client_step(¤t_process->simulation_client, contexts, polled, num_polled, &timeout);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -688,7 +688,17 @@ void update_simulation(void)
|
|||||||
|
|
||||||
case CONNECTION_DELAYED:
|
case CONNECTION_DELAYED:
|
||||||
{
|
{
|
||||||
printf("Resolving connect\n"); // TODO
|
switch (desc->connect_address.type) {
|
||||||
|
char ip_str[INET_ADDRSTRLEN];
|
||||||
|
case DESC_ADDR_IPV4:
|
||||||
|
inet_ntop(AF_INET, &desc->connect_address.ipv4.sin_addr, ip_str, sizeof(ip_str));
|
||||||
|
printf("Resolving connect %s:%d\n", ip_str, ntohs(desc->connect_address.ipv4.sin_port));
|
||||||
|
break;
|
||||||
|
case DESC_ADDR_IPV6:
|
||||||
|
inet_ntop(AF_INET6, &desc->connect_address.ipv6.sin6_addr, ip_str, sizeof(ip_str));
|
||||||
|
printf("Resolving connect %s:%d\n", ip_str, ntohs(desc->connect_address.ipv6.sin6_port));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
DescriptorHandle peer_handle;
|
DescriptorHandle peer_handle;
|
||||||
if (!find_peer_by_address(desc->connect_address, &peer_handle)) {
|
if (!find_peer_by_address(desc->connect_address, &peer_handle)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user