···2626 UUID fid; ///< File ID (foreign from INode) default 0
2727 UUID nid; ///< Node ID (foreign from DNode) default 0
2828 UUID cid; ///< Chunk ID default ""
2929+ size_t seq; ///< The order of this chunk
2930} Block;
30313132DefList(Block)
···6566/// @param fid UUID of file's INode or NULL
6667/// @param nid UUID of DNode or NULL
6768/// @param cid string representing Block's chunk ID or NULL
6868-void insert_into_block(UUID* fid, UUID* nid, UUID* cid);
6969+void insert_into_block(UUID* fid, UUID* nid, UUID* cid, size_t* seq);
69707071/// SELECT from the Block table.
7172///
···7475/// @param nid the Block's DNode's UUID or NULL
7576/// @param cid the Block's chunk ID or NULL
7677/// @return a ListBlock of the possible matches
7777-ListBlock select_from_block(UUID* bid, UUID* fid, UUID* nid, UUID* cid);
7878+ListBlock select_from_block(UUID* bid, UUID* fid, UUID* nid, UUID* cid, size_t* seq);
78797980/// Get the Block table from the database.
8081///
···3030 Port port; ///< Port of where the connection came from
3131} DNode;
32323333-DefList(DNode)
34333434+/// This carries all the necessary information that a chunk should have.
3535typedef struct {
3636- IPv4 address;
3737- Port port;
3838- UUID cid;
3636+ DNode dnode; ///< the DNode of the chunk
3737+ UUID cid; ///< The UUID of the chunk
3838+ size_t seq; ///< The place in the sequence of chunks where this chunk should be
3939} DNodeInfo;
40404141+DefList(DNodeInfo)
4242+4343+DefList(DNode)
4444+4145Buffer DNodeInfo_serialize(DNodeInfo dinfo);
42464347DNodeInfo DNodeInfo_deserialize(Buffer buf);
44484545-DefList(DNodeInfo)
4646-4749Buffer ListDNodeInfo_serialize(ListDNodeInfo list);
48504951ListDNodeInfo ListDNodeInfo_deserialize(Buffer buf);
5050-51525253/// Serialize a DNode into a Buffer.
5354/// Caller must free memory in Buffer.buf.
+14-2
src/lib/enchufe.c
···156156 return concat(Tag_serialize(command.tag), concat(size_t_serialize(command.as.put.fsize), SafeStr_serialize(command.as.put.fname)));
157157 case WRITE:
158158 return concat(Tag_serialize(command.tag), size_t_serialize(command.as.write.nbytes));
159159+ case READ:
160160+ return concat(Tag_serialize(command.tag), UUID_serialize(command.as.read.cid));
159161 default:
160162 fprintf(stderr, "ERROR: Tried to serialize a command in a wrong way.\n");
161163 exit(1);
···192194 .fname = SafeStr_deserialize((Buffer){ .buf = buf.buf + sizeof(enum Tag) + sizeof(size_t), .len = 0 }),
193195 }
194196 };
195195- case WRITE: {
197197+ case WRITE:
196198 return (Command){
197199 .tag = tag,
198200 .as.write.nbytes = size_t_deserialize((Buffer){ .buf = buf.buf + sizeof(enum Tag), .len = sizeof(size_t)}),
199201 };
200200- } break;
202202+ case READ: {
203203+ // INFO: This is necessary to avoid the padding that the C compiler
204204+ // introduces. This padding shows up in sizeof() but not in the
205205+ // Buffer itself.
206206+ Buffer tmp = UUID_serialize((UUID){0});
207207+ free(tmp.buf);
208208+ return (Command){
209209+ .tag = tag,
210210+ .as.read.cid = UUID_deserialize((Buffer){ .buf = buf.buf + sizeof(enum Tag), .len = tmp.len }),
211211+ };
212212+ } break;
201213 default:
202214 fprintf(stderr, "ERROR: Tried to serialize a command in a wrong way.\n");
203215 exit(1);