// // Created by haraldwolff on 07.08.22. // #include #include #include /* int bs_recv_linear_tx(bsync_engine_t *engine); int bs_recv_linear(bsync_engine_t *engine){ char *block = malloc(engine->blocksize); if (!block) { fprintf(stderr, "no memory available for block"); exit(EXIT_FAILURE); } long offset = 0; long residual; pthread_t thread_tx; int s = pthread_create(&thread_tx, NULL, (void *(*)(void *)) bs_recv_linear_tx, engine); if (s != 0){ fprintf(stderr, "could not create tx thread\n"); fflush(stderr); exit(EXIT_FAILURE); } while (-1){ if (bs_recv(engine->remote, &offset, sizeof(offset)) == -1){ fprintf(stderr, "could not receive offset\n"); exit(EXIT_FAILURE); } if (offset == -1ul){ break; } residual = engine->filesize - offset; int32_t size = residual > engine->blocksize ? engine->blocksize : residual; if (bs_recv(engine->remote, block, size) == -1){ fprintf(stderr, "could not receive block at offset 0x%lx\n", offset); exit(EXIT_FAILURE); } engine->stat_blocks++; engine->stat_block_bytes += size; //fprintf(stderr, "received block with %d bytes @ offset 0x%lx\n", size, offset); if (!(engine->tool_flags & BS_SIMULATE)) { if (write_block(engine, offset, block, size) != size) exit(EXIT_FAILURE); } } engine->tool_flags |= BS_SHUTDOWN; pthread_join(thread_tx, NULL); dump_engine_state(engine); fprintf( stdout, "\n"); } int bs_recv_linear_tx(bsync_engine_t *engine){ char *block = malloc(engine->blocksize); if (!block) { fprintf(stderr, "no memory available for block"); exit(EXIT_FAILURE); } long offset = 0; long residual = engine->filesize; while (residual > 0){ int32_t size = residual > engine->blocksize ? engine->blocksize : residual; uint64_t blockhash, remotehash; if (read_block(engine, offset, block, size) != size) exit(EXIT_FAILURE); blockhash = dhash( block, size); int percent = 100 * offset / engine->filesize; if ( (bs_send(engine->remote, &offset, sizeof(offset)) == -1) || (bs_send(engine->remote, &blockhash, sizeof(blockhash)) == -1) ) { fprintf(stderr, "could not send block hash at offset 0x%lx\n", offset); exit(EXIT_FAILURE); } engine->last_offset = offset; time_t t = time(NULL); if (engine->t_last_update != t) dump_engine_state(engine); offset += size; residual -= size; } offset = -1l; if (bs_send(engine->remote, &offset, sizeof(offset)) == -1) { fprintf(stderr, "could not send end mark\n"); exit(EXIT_FAILURE); } while (!(engine->tool_flags & BS_SHUTDOWN)) { sleep(1); dump_engine_state(engine); } return 0; } */