// // Created by haraldwolff on 07.08.22. // #include #include #include /* int bs_send_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; if (engine->tool_flags & BS_VERBOSE){ fprintf(stdout, "size: %ld bytes, blocksize: %d bytes\n", engine->filesize, engine->blocksize); fflush(stdout); } 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; uint64_t blockhash, remotehash; if (bs_recv(engine->remote, &remotehash, sizeof(remotehash)) == -1){ fprintf(stderr, "could not receive block hash at offset 0x%lx\n", offset); exit(EXIT_FAILURE); } if (read_block(engine, offset, block, size) != size) exit(EXIT_FAILURE); blockhash = dhash( block, size); int percent = 100 * offset / engine->filesize; if (remotehash != blockhash){ fprintf(stdout, "offset: %d bytes @ 0x%lx (%d%%) [0x%lx] differs \n", size, offset, percent, blockhash); fflush(stdout); if ( (bs_send(engine->remote, &offset, sizeof(offset)) == -1) || (bs_send(engine->remote, block, size) == -1) ){ fprintf(stderr,"could not send block at offset 0x%lx\n", offset); fprintf(stderr,"errno=%d (%s)", errno, strerror(errno)); exit(EXIT_FAILURE); } engine->stat_blocks++; engine->stat_block_bytes += size; 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); } dump_engine_state(engine); fprintf( stdout, "\n"); } */