Distributed File System 1
Distributed file system in C
Loading...
Searching...
No Matches
enchufe.h
Go to the documentation of this file.
1/* lib/enchufe.h
2 *
3 * ¡Esta es la librería de Enchufe!
4 *
5 */
6#ifndef ENCHUFE_H_
7#define ENCHUFE_H_
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13/* ----- Includes ----- */
14
15#include <netinet/in.h>
16#include <stdlib.h>
17#include <string.h>
18#include <sys/socket.h>
19#include "lib.h"
20#include "uuid.h"
21
22/* ----- Types ----- */
23
25typedef int FD;
26
28typedef uint16_t Port;
29
33typedef union {
35 uint32_t ip;
36} IPv4;
37
39typedef struct {
41 struct sockaddr_in addr;
42 socklen_t addrlen;
43} Enchufe;
44
46typedef struct {
47 struct sockaddr_in addr;
48 socklen_t addrlen;
50
52typedef struct {
62 union {
63 struct {
66 } reg;
67 struct {
69 } get;
70 struct {
71 size_t fsize;
73 } put;
74 struct {
75 size_t nbytes;
76 } write;
77 struct {
79 } read;
80 } as ;
81} Command;
82
83/* ----- Functions ----- */
84
90
96
99FD nuevo(void);
100
106
114inline Enchufe aplasta(FD fd, Receptaculo rec) {
115 return (Enchufe){
116 .fd = fd,
117 .addr = rec.addr,
118 .addrlen = rec.addrlen,
119 };
120}
121
127Enchufe enchufa(IPv4 ip, Port port);
128
132void conecta(Enchufe enchufe);
133
141void amarra(Enchufe enchufe);
142
149void escucha(Enchufe enchufe, size_t len);
150
157Enchufe acepta(Enchufe enchufe);
158
163void zumba(Enchufe enchufe, Buffer in_buf);
164
172size_t recibe(Enchufe enchufe, Buffer out_buf);
173
177void desenchufa(Enchufe enchufe);
178
185
191
197
203
209
214Buffer Tag_serialize(enum Tag tag);
215
220enum Tag Tag_deserialize(Buffer buf);
221
222
223
224#ifdef __cplusplus
225}
226#endif
227
228#endif // ENCHUFE_H_ header
Enchufe aplasta(FD fd, Receptaculo rec)
Coge un file descriptor y un receptaculo y los junta.
Definition enchufe.h:114
void desenchufa(Enchufe enchufe)
Esta funcion se encarga de liberar los recursos que ocupan los echufes.
Definition enchufe.c:72
Buffer Tag_serialize(enum Tag tag)
Serialize a Tag to a Buffer.
Definition enchufe.c:119
Command Command_deserialize(Buffer buf)
Deserialize a Command from a Buffer.
Definition enchufe.c:156
IPv4 parse_address(Str str)
Esta funcion convierte un string que representa un IPv4 en un IPv4.
Definition enchufe.c:94
Buffer Port_serialize(Port port)
Convierte un puerto a Byte's.
Definition enchufe.c:75
Buffer Command_serialize(Command command)
Serialize a Command to a Buffer.
Definition enchufe.c:134
enum Tag Tag_deserialize(Buffer buf)
Deserialize a Tag from a Buffer.
Definition enchufe.c:123
void amarra(Enchufe enchufe)
Amarra la direccion de IP que se le dio al enchufe, al file descriptor.
Definition enchufe.c:39
int FD
File descriptor.
Definition enchufe.h:25
size_t recibe(Enchufe enchufe, Buffer out_buf)
Recibe un buffer de bytes de un cliente.
Definition enchufe.c:65
Receptaculo receptaculo(IPv4 ip, Port port)
Crea un receptaculo.
Definition enchufe.c:14
FD nuevo(void)
Crea un file descriptor nuevo para un enchufe.
Definition enchufe.c:8
Buffer IPv4_serialize(IPv4 ip)
Convierte un IPv4 a un Buffer.
Definition enchufe.c:110
IPv4 IPv4_deserialize(Buffer buf)
Convierte un Buffer a un IPv4.
Definition enchufe.c:114
void zumba(Enchufe enchufe, Buffer in_buf)
Envia un buffer de bytes a un cliente.
Definition enchufe.c:60
void escucha(Enchufe enchufe, size_t len)
Le deja saber al enchufe cuantas conexiones se pueden hacer.
Definition enchufe.c:44
Port Port_deserialize(Buffer buf)
Convierte un Buffer a un puerte.
Definition enchufe.c:86
void conecta(Enchufe enchufe)
Crea la conexion desde tu computadora hasta donde sea que este el enchufe.
Definition enchufe.c:34
uint16_t Port
El puerto de la conexion.
Definition enchufe.h:28
Enchufe enchufa(IPv4 ip, Port port)
Crea un enchufe sin abrir la conexion.
Definition enchufe.c:29
Enchufe acepta(Enchufe enchufe)
Bloquea el thread hasta que un cliente se conecte.
Definition enchufe.c:49
const char * Str
String type.
Definition lib.h:73
uint8_t Byte
Simple Byte type. Guaranteed to be exactly 8 bits.
Definition lib.h:70
void put(Enchufe cliente, size_t fsize, SafeStr fname)
Puts file data on the server.
Definition meta-data.c:45
void get(Enchufe cliente, SafeStr fname)
Get file data from server.
Definition meta-data.c:88
void reg(IPv4 address, Port port)
Registers a data node.
Definition meta-data.c:30
Byte buffer.
Definition lib.h:92
Estructura para enviar distintos Command's por el socket.
Definition enchufe.h:52
Port port
el puerto del data node
Definition enchufe.h:65
SafeStr fname
el nombre del archivo
Definition enchufe.h:68
Tag
Definition enchufe.h:53
@ LIST
Definition enchufe.h:56
@ PUT
Definition enchufe.h:58
@ GET
Definition enchufe.h:57
@ READ
Definition enchufe.h:60
@ REG
Definition enchufe.h:55
@ ACK
Definition enchufe.h:54
@ WRITE
Definition enchufe.h:59
IPv4 address
el IP del data node
Definition enchufe.h:64
size_t fsize
el tamaño del archivo
Definition enchufe.h:71
UUID cid
el UUID del chunk que se esta buscando
Definition enchufe.h:78
size_t nbytes
la cantidad de Byte's que se estaran escribiendo
Definition enchufe.h:75
Enchufe para la conexion.
Definition enchufe.h:39
struct sockaddr_in addr
la data de conexion
Definition enchufe.h:41
socklen_t addrlen
la longitud en Byte's de la data de conexion
Definition enchufe.h:42
FD fd
El File Descriptor de la conexion.
Definition enchufe.h:40
Receptaculo para la conexion.
Definition enchufe.h:46
socklen_t addrlen
la longitud de la data de conexion
Definition enchufe.h:48
struct sockaddr_in addr
la data de conexion
Definition enchufe.h:47
Safe String type.
Definition lib.h:76
UUID type Layout taken from: https://en.wikipedia.org/wiki/Universally_unique_identifier#Binary_repre...
Definition uuid.h:24
Tipo para un IPv4 Ademas te ayuda convertir entre little endian y big endian.
Definition enchufe.h:33
Byte bytes[4]
interpreta el IP como Byte's
Definition enchufe.h:34
uint32_t ip
Interpreta el IP como un uint32_t.
Definition enchufe.h:35