This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathpacket.h
112 lines (91 loc) · 2.47 KB
/
packet.h
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
This file is part of duckOS.
duckOS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
duckOS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with duckOS. If not, see <https://www.gnu.org/licenses/>.
Copyright (c) Byteduck 2016-2021. All rights reserved.
*/
#pragma once
#include <vector>
#include <string>
#include <libduck/Result.h>
#include <sys/socketfs.h>
#include <poll.h>
#include <cstring>
#define LIBRIVER_PACKET_MAGIC 0xBEEF420
#define LIBRIVER_MAX_TARGET_NAME_LEN 1024
namespace River {
enum PacketType {
SOCKETFS_CLIENT_CONNECTED = -1,
SOCKETFS_CLIENT_DISCONNECTED = -2,
CLIENT_CONNECTED = 1,
CLIENT_DISCONNECTED = 2,
REGISTER_ENDPOINT = 10,
GET_ENDPOINT = 11,
FUNCTION_CALL = 20,
FUNCTION_RETURN = 21,
REGISTER_FUNCTION = 22,
GET_FUNCTION = 23,
REGISTER_MESSAGE = 24,
GET_MESSAGE = 26,
SEND_MESSAGE = 25,
DEREGISTER_PATH = 30
};
enum ErrorType {
SUCCESS = 0,
UNKNOWN_ERROR = 1,
ENDPOINT_ALREADY_REGISTERED = 3,
ENDPOINT_DOES_NOT_EXIST = 4,
FUNCTION_ALREADY_REGISTERED = 5,
FUNCTION_DOES_NOT_EXIST = 6,
MALFORMED_DATA = 7,
ILLEGAL_REQUEST = 8,
MESSAGE_ALREADY_REGISTERED = 9,
MESSAGE_DOES_NOT_EXIST = 10,
MESSAGE_HANDLER_ALREADY_SET = 11
};
const char* error_str(int type);
struct RawPacket {
int __river_magic = LIBRIVER_PACKET_MAGIC;
PacketType type;
size_t path_length; //Incl. null terminator
size_t data_length;
ErrorType error;
sockid_t id;
uint8_t data[];
};
struct RiverPacket {
PacketType type;
std::string endpoint;
std::string path;
union {
ErrorType error;
pid_t connected_pid;
pid_t disconnected_pid;
};
union {
sockid_t recipient;
sockid_t sender;
sockid_t connected_id;
sockid_t disconnected_id;
};
sockid_t __socketfs_from_id;
pid_t __socketfs_from_pid;
std::vector<uint8_t> data;
};
enum PacketReadResult {
PACKET_READ = 0,
NO_PACKET,
PACKET_ERR,
SOCKETFS_MESSAGE,
};
Duck::ResultRet<RiverPacket> receive_packet(int fd, bool block);
Duck::Result send_packet(int fd, sockid_t recipient, const RiverPacket& packet);
}