@@ -276,16 +276,15 @@ static void forwardCreated(Circuit* circuit, ControlCell cell) {
276276
277277// Sends data towards the other end of the circuit. If the data is larger than
278278// the maximum payload size, it will be split into multiple cells and sent sequentially.
279- static void sendData (Circuit* circuit, uint16_t nextNodeID, uint16_t circID, uint8_t * data, size_t length, bool direction) {
279+ static void sendData (Circuit* circuit, uint16_t nextNodeID, uint16_t circID, uint8_t * data,
280+ size_t length, bool direction, RelayCellCommand command = DATA ) {
280281 uint16_t maxPayload = CELL_SIZE - RELAY_HEADER_SIZE - HASH_SIZE ;
281282 uint16_t offset = 0 ; // keep track of how much of the data has been sent
282- printf (" after entry check\n " );
283283 while (offset < length) {
284- printf (" loop, offset: %d, total: %zu, max space: %d\n " , offset, length, maxPayload);
285284 uint16_t size = (length - offset) < maxPayload ? (length - offset) : maxPayload; // payload size
286285 // fill the information cell
287286 RelayCell dataCell;
288- fillRelayCell (dataCell, circID, RelayCellCommand:: DATA , nodeID, nextNodeID, size);
287+ fillRelayCell (dataCell, circID, command , nodeID, nextNodeID, size);
289288 memcpy (dataCell.payload , data + offset, size);
290289 // write zeroes to remaining payload, prevent leakage of previous data if payload is smaller than max
291290 memset (dataCell.payload + size, 0 , maxPayload - size);
@@ -326,9 +325,10 @@ void sendDataForwards(Circuit* circuit, uint8_t* data, size_t length) {
326325}
327326
328327// function to send a RELAY DATA cell towards the origin.
329- void sendDataBackwards (Circuit* circuit, uint16_t prevNodeID, uint16_t prevCircID, uint8_t * data, size_t length) {
328+ void sendDataBackwards (Circuit* circuit, uint16_t prevNodeID, uint16_t prevCircID,
329+ uint8_t * data, size_t length, RelayCellCommand command = DATA ) {
330330 printf (" sendDataBackwards\n " );
331- sendData (circuit, prevNodeID, prevCircID, data, length, false );
331+ sendData (circuit, prevNodeID, prevCircID, data, length, false , command );
332332}
333333
334334// checks the validity of the digest, and returns a buffer with the content of the message.
@@ -359,9 +359,9 @@ static void handleDataAtExit(Circuit* circuit, RelayCell cell) {
359359 uint8_t buffer[CELL_SIZE - RELAY_HEADER_SIZE - HASH_SIZE ];
360360 uint8_t * result = handleData (circuit, cell, buffer);
361361 if (result != nullptr ) {
362- printf (" Received data: %s\n " , result);
362+ printf (" Circuit %d: Received data: %s\n " , circuit-> circID , result);
363363 const char * msg = " Data received successfully!" ;
364- sendDataBackwards (circuit, cell.srcNodeID , cell.circID , (uint8_t *)msg, strlen (msg) + 1 );
364+ sendDataBackwards (circuit, cell.srcNodeID , cell.circID , (uint8_t *)msg, strlen (msg) + 1 , DATA_ACK );
365365 }
366366}
367367
@@ -645,6 +645,9 @@ static void dispatchRelay(Circuit* circuit, uint8_t* data, uint16_t circID) {
645645 case DATA :
646646 handleDataAtExit (circuit, cell);
647647 break ;
648+ case DATA_ACK :
649+ handleDataAtOrigin (circuit, copy);
650+ break ;
648651 default :
649652 break ;
650653 }
0 commit comments