summaryrefslogtreecommitdiff
path: root/include/peer.h
blob: f6baa4bc0a19ee7a65406a4a039fb1ce00ffafdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-FileCopyrightText: 2024 Lizzy Fleckenstein <lizzy@vlhl.dev>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

#ifndef PEER_H
#define PEER_H

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <poll.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);
struct pollfd peer_prepare(peer *p);
bool peer_ready(peer *p, struct pollfd revents);
bool peer_send(peer *p, void *data, size_t len);

#endif