summaryrefslogtreecommitdiff
path: root/peer.h
diff options
context:
space:
mode:
Diffstat (limited to 'peer.h')
-rw-r--r--peer.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/peer.h b/peer.h
new file mode 100644
index 0000000..f6b9b50
--- /dev/null
+++ b/peer.h
@@ -0,0 +1,36 @@
+#ifndef PEER_H
+#define PEER_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+#define PEER_INBUFFER_SIZE 0x100000 // 1MB
+#define PEER_OUTBUFFER_SIZE 0x200000 // 2MB
+
+typedef uint32_t pkt_header;
+
+typedef struct {
+ int socket;
+ bool disco;
+ struct {
+ bool header;
+ size_t len;
+ size_t promised;
+ uint8_t *buffer;
+ } in;
+ // TODO: ring buffer
+ struct {
+ size_t avail;
+ size_t cursor;
+ uint8_t *buffer;
+ } out;
+} peer;
+
+void peer_init(peer *p, int socket);
+void peer_free(peer *p);
+short peer_prepare(peer *p);
+bool peer_ready(peer *p, short revents);
+bool peer_send(peer *p, uint8_t *data, size_t len);
+
+#endif