Skip to content

Feature/ftp - #157

Draft
victorsowa12 wants to merge 5 commits into
mainfrom
feature/ftp
Draft

victorsowa12 wants to merge 5 commits into
mainfrom
feature/ftp

Conversation

@victorsowa12

Copy link
Copy Markdown
Contributor

What changed?

How does it make Bristlemouth better?

Where should reviewers focus?

Checklist

  • Add or update unit tests for changed code
  • Ensure all submodules up to date. If this PR relies on changes in submodules, merge those PRs first, then point this PR at/after the merge commit
  • Ensure code is formatted correctly with clang-format. If there are large formatting changes, they should happen in a separate whitespace-only commit on this PR after all approvals.

@matt001k matt001k left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the most part it looks good, I think we should consider maybe doing something different with the endpoint logic although. Happy to discuss when you are back!

Comment thread bcmp/packet.c
Comment on lines +202 to +254
case BcmpFTPStartMessage: {
BmFtpStart *start = (BmFtpStart *)buf;
swap_ftp_address(&start->addresses);
swap_32bit(&start->transfer_id);
swap_32bit(&start->total_size);
swap_16bit(&start->requested_chunk_size);
swap_16bit(&start->crc16);
swap_16bit(&start->sink_spec_len);
} break;
case BcmpFTPAckMessage: {
BmFtpAck *ack = (BmFtpAck *)buf;
swap_ftp_address(&ack->addresses);
swap_32bit(&ack->transfer_id);
swap_32bit(&ack->total_size);
swap_16bit(&ack->crc16);
swap_16bit(&ack->chunk_size);
} break;
case BcmpFTPChunkReqMessage: {
BmFtpChunkRequest *request = (BmFtpChunkRequest *)buf;
swap_ftp_address(&request->addresses);
swap_32bit(&request->transfer_id);
swap_32bit(&request->offset);
swap_16bit(&request->length);
swap_16bit(&request->reserved);
} break;
case BcmpFTPChunkMessage: {
BmFtpChunk *chunk = (BmFtpChunk *)buf;
swap_ftp_address(&chunk->addresses);
swap_32bit(&chunk->transfer_id);
swap_32bit(&chunk->offset);
swap_16bit(&chunk->payload_length);
swap_16bit(&chunk->reserved);
} break;
case BcmpFTPEndMessage: {
BmFtpEnd *end = (BmFtpEnd *)buf;
swap_ftp_address(&end->addresses);
swap_32bit(&end->transfer_id);
swap_16bit(&end->reserved);
swap_32bit(&end->bytes_received);
swap_16bit(&end->running_crc16);
swap_16bit(&end->reserved2);
} break;
case BcmpFTPAbortMessage: {
BmFtpAbort *abort = (BmFtpAbort *)buf;
swap_ftp_address(&abort->addresses);
swap_32bit(&abort->transfer_id);
} break;
case BcmpFTPFetchMessage: {
BmFtpFetch *fetch = (BmFtpFetch *)buf;
swap_ftp_address(&fetch->addresses);
swap_32bit(&fetch->transfer_id);
swap_16bit(&fetch->source_spec_len);
} break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should get rid of this endian swap logic, or move the logic for each swap to its own file, it adds a lot of noise to this file in general.
Should not be done now, but I will make an issue in the repo.

Comment thread bcmp/ftp_core.c
}
}

static void bm_ftp_event_thread(void *parameters) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little hesitant to add more threads to bm_core, but maybe a later task can be to determine how we can reduce the number of threads? But there is the potential overhead of writing to/reading from flash that makes having another task good for this purpose.
Something to think about.


// I'm not sure if I want these, or if I want
// the nodes to define them arbitrarily themselves.
typedef enum {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the point of the different endpoints?
Thinking about the Spotter Bridge, it has onboard flash and potential access to the Spotter's SD card.
Could all of these files be represented as a single entity agnostic to the endpoint it comes from?
Do nodes care if it is being accessed over bm_serial or internally on flash?
I can see the spec of a file on the Bridge being prepended with /bridge/{file_name} or /spotter/{file_name} as the way to delineate where the file is coming from (or going to), that way it leaves the transfer agnostic to the endpoint and everytime a new endpoint kind comes up this does not have to be updated.

Comment thread bcmp/ftp_coordinator.c
Comment on lines +189 to +194
if (coordinator.state != BmFtpCoordinatorReceiving ||
chunk->addresses.src_node_id != coordinator.peer_node_id ||
chunk->transfer_id != coordinator.transfer_id ||
chunk->offset != coordinator.bytes_received || chunk->payload_length == 0 ||
chunk->payload_length > coordinator.chunk_size ||
chunk->payload_length > coordinator.total_size - coordinator.bytes_received) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional is pretty long, it would be nice to clean this up into some boolean variables that can be condensed down, i.e.:

bool payload_len_invalid = chunk->payload_length > coordinator.chunk_size ||
      chunk->payload_length > coordinator.total_size - coordinator.bytes_received;
bool transfer_invalid = chunk->transfer_id != coordinator.transfer_id ||
      chunk->offset != coordinator.bytes_received || chunk->payload_length == 0;

if (coordinator.state != BmFtpCoordinatorReceiving ||
    chunk->addresses.src_node_id != coordinator.peer_node_id ||
    payload_len_invalid || transfer_invalid) {
  return BmEBADMSG;
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants