Skip to content
This repository was archived by the owner on Jul 2, 2021. It is now read-only.

sip9 #446

Merged
merged 2 commits into from
May 4, 2018
Merged

sip9 #446

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions src/downloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
static void free_exchange_report(storj_exchange_report_t *report)
{
free(report->data_hash);
free(report->reporter_id);
free(report->farmer_id);
free(report->client_id);
free(report->token);
free(report);
}

Expand Down Expand Up @@ -260,14 +258,11 @@ static void set_pointer_from_json(storj_download_state_t *state,
return;
}

const char *client_id = state->env->bridge_options->user;
p->report->reporter_id = strdup(client_id);
p->report->client_id = strdup(client_id);
p->report->data_hash = strdup(hash);
if (farmer_id) {
p->report->farmer_id = strdup(farmer_id);
if (token) {
p->report->token = strdup(token);
} else {
p->report->farmer_id = NULL;
p->report->token = NULL;
}
p->report->send_status = 0; // not sent
p->report->send_count = 0;
Expand Down Expand Up @@ -494,15 +489,15 @@ static void queue_request_pointers(storj_download_state_t *state)
state->log->debug(state->env->log_options,
state->handle,
"Adding farmer_id %s to excluded list",
pointer->report->farmer_id);
pointer->farmer_id);

if (!state->excluded_farmer_ids) {
state->excluded_farmer_ids = calloc(42, sizeof(char));
if (!state->excluded_farmer_ids) {
state->error_status = STORJ_MEMORY_ERROR;
return;
}
strcat(state->excluded_farmer_ids, pointer->report->farmer_id);
strcat(state->excluded_farmer_ids, pointer->farmer_id);
} else {
state->excluded_farmer_ids =
realloc(state->excluded_farmer_ids,
Expand All @@ -512,7 +507,7 @@ static void queue_request_pointers(storj_download_state_t *state)
return;
}
strcat(state->excluded_farmer_ids, ",");
strcat(state->excluded_farmer_ids, pointer->report->farmer_id);
strcat(state->excluded_farmer_ids, pointer->farmer_id);
}

json_request_replace_pointer_t *req =
Expand Down Expand Up @@ -894,14 +889,8 @@ static void send_exchange_report(uv_work_t *work)
json_object_object_add(body, "dataHash",
json_object_new_string(req->report->data_hash));

json_object_object_add(body, "reporterId",
json_object_new_string(req->report->reporter_id));

json_object_object_add(body, "farmerId",
json_object_new_string(req->report->farmer_id));

json_object_object_add(body, "clientId",
json_object_new_string(req->report->client_id));
json_object_object_add(body, "token",
json_object_new_string(req->report->token));

json_object_object_add(body, "exchangeStart",
json_object_new_int64(req->report->start));
Expand Down
4 changes: 1 addition & 3 deletions src/storj.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,7 @@ static const char *BUCKET_OP[] = { "PUSH", "PULL" };
*/
typedef struct {
char *data_hash;
char *reporter_id;
char *farmer_id;
char *client_id;
char *token;
uint64_t start;
uint64_t end;
unsigned int code;
Expand Down
23 changes: 7 additions & 16 deletions src/uploader.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,8 @@ static storj_exchange_report_t *storj_exchange_report_new()
return NULL;
}
report->data_hash = NULL;
report->reporter_id = NULL;
report->farmer_id = NULL;
report->client_id = NULL;
report->token = NULL;
report->message = NULL;

report->send_status = STORJ_REPORT_NOT_PREPARED; // not sent
report->start = 0;
report->end = 0;
Expand Down Expand Up @@ -848,7 +845,7 @@ static void queue_push_shard(storj_upload_state_t *state, int index)

state->shard[index].progress = PUSHING_SHARD;

if (state->shard[index].report->farmer_id != NULL) {
if (state->shard[index].report->token != NULL) {
free(state->shard[index].report);
state->shard[index].report = storj_exchange_report_new();
}
Expand All @@ -861,9 +858,7 @@ static void queue_push_shard(storj_upload_state_t *state, int index)
// setup the exchange report
storj_exchange_report_t *report = state->shard[index].report;
report->data_hash = state->shard[index].meta->hash;
report->reporter_id = (char *)state->env->bridge_options->user;
report->farmer_id = state->shard[index].pointer->farmer_node_id;
report->client_id = (char *)state->env->bridge_options->user;
report->token = state->shard[index].pointer->token;
report->pointer_index = index;
report->start = 0;
report->end = 0;
Expand Down Expand Up @@ -2035,14 +2030,8 @@ static void send_exchange_report(uv_work_t *work)
json_object_object_add(body, "dataHash",
json_object_new_string(req->report->data_hash));

json_object_object_add(body, "reporterId",
json_object_new_string(req->report->reporter_id));

json_object_object_add(body, "farmerId",
json_object_new_string(req->report->farmer_id));

json_object_object_add(body, "clientId",
json_object_new_string(req->report->client_id));
json_object_object_add(body, "token",
json_object_new_string(req->report->token));

json_object_object_add(body, "exchangeStart",
json_object_new_int64(req->report->start));
Expand All @@ -2065,6 +2054,8 @@ static void send_exchange_report(uv_work_t *work)
"/reports/exchanges", body,
true, &response, &status_code);

state->log->warn(state->env->log_options, state->handle,
"Sent exchange report : %s", json_object_to_json_string(body));

if (request_status) {
state->log->warn(state->env->log_options, state->handle,
Expand Down