join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
protocol.hpp
Go to the documentation of this file.
1
25#ifndef JOIN_CORE_PROTOCOL_HPP
26#define JOIN_CORE_PROTOCOL_HPP
27
28// libjoin.
29#include <join/endpoint.hpp>
30
31// C.
32#include <linux/netlink.h>
33#include <net/ethernet.h>
34
35namespace join
36{
37 template <class Protocol>
38 class BasicSocket;
39 template <class Protocol>
40 class BasicDatagramSocket;
41 template <class Protocol>
42 class BasicStreamSocket;
43 template <class Protocol>
44 class BasicTlsSocket;
45
46 template <class Protocol>
47 class BasicSocketStream;
48 template <class Protocol>
49 class BasicTlsStream;
50
51 template <class Protocol>
53 template <class Protocol>
55
56 template <class Protocol>
58 template <class Protocol>
59 class BasicTlsResolver;
60
61 template <class Protocol>
62 class BasicHttpClient;
63 template <class Protocol>
65
66 template <class Protocol>
67 class BasicHttpWorker;
68 template <class Protocol>
69 class BasicHttpServer;
70 template <class Protocol>
72
73 template <class Protocol>
74 class BasicSmtpClient;
75 template <class Protocol>
77
82 {
83 public:
86
90 constexpr UnixDgram () noexcept = default;
91
96 constexpr int family () const noexcept
97 {
98 return AF_UNIX;
99 }
100
105 constexpr int type () const noexcept
106 {
107 return SOCK_DGRAM;
108 }
109
114 constexpr int protocol () const noexcept
115 {
116 return 0;
117 }
118 };
119
124 {
125 public:
130
134 constexpr UnixStream () noexcept = default;
135
140 constexpr int family () const noexcept
141 {
142 return AF_UNIX;
143 }
144
149 constexpr int type () const noexcept
150 {
151 return SOCK_STREAM;
152 }
153
158 constexpr int protocol () const noexcept
159 {
160 return 0;
161 }
162 };
163
168 {
169 public:
172
177 constexpr Netlink (int proto = NETLINK_ROUTE) noexcept
178 : _proto (proto)
179 {
180 }
181
186 static inline Netlink& rt () noexcept
187 {
188 static Netlink route (NETLINK_ROUTE);
189 return route;
190 }
191
196 static inline Netlink& nf () noexcept
197 {
198 static Netlink netfilter (NETLINK_NETFILTER);
199 return netfilter;
200 }
201
206 constexpr int family () const noexcept
207 {
208 return AF_NETLINK;
209 }
210
215 constexpr int type () const noexcept
216 {
217 return SOCK_RAW;
218 }
219
224 constexpr int protocol () const noexcept
225 {
226 return _proto;
227 }
228
229 private:
231 int _proto;
232 };
233
240 constexpr bool operator== (const Netlink& a, const Netlink& b) noexcept
241 {
242 return a.protocol () == b.protocol ();
243 }
244
251 constexpr bool operator!= (const Netlink& a, const Netlink& b) noexcept
252 {
253 return !(a == b);
254 }
255
259 class Raw
260 {
261 public:
264
268 constexpr Raw () noexcept = default;
269
274 constexpr int family () const noexcept
275 {
276 return AF_PACKET;
277 }
278
283 constexpr int type () const noexcept
284 {
285 return SOCK_RAW;
286 }
287
292 constexpr int protocol () const noexcept
293 {
294 if (BYTE_ORDER == LITTLE_ENDIAN)
295 {
296 return (ETH_P_ALL >> 8) | (ETH_P_ALL << 8);
297 }
298 return ETH_P_ALL;
299 }
300 };
301
305 class Udp
306 {
307 public:
310
315 constexpr Udp (int family = AF_INET) noexcept
316 : _family (family)
317 {
318 }
319
324 static inline Udp& v4 () noexcept
325 {
326 static Udp udpv4 (AF_INET);
327 return udpv4;
328 }
329
334 static inline Udp& v6 () noexcept
335 {
336 static Udp udpv6 (AF_INET6);
337 return udpv6;
338 }
339
344 constexpr int family () const noexcept
345 {
346 return _family;
347 }
348
353 constexpr int type () const noexcept
354 {
355 return SOCK_DGRAM;
356 }
357
362 constexpr int protocol () const noexcept
363 {
364 return IPPROTO_UDP;
365 }
366
367 private:
369 int _family;
370 };
371
378 constexpr bool operator== (const Udp& a, const Udp& b) noexcept
379 {
380 return a.family () == b.family ();
381 }
382
389 constexpr bool operator!= (const Udp& a, const Udp& b) noexcept
390 {
391 return !(a == b);
392 }
393
397 class Icmp
398 {
399 public:
402
407 constexpr Icmp (int family = AF_INET) noexcept
408 : _family (family)
409 {
410 }
411
416 static inline Icmp& v4 () noexcept
417 {
418 static Icmp icmpv4 (AF_INET);
419 return icmpv4;
420 }
421
426 static inline Icmp& v6 () noexcept
427 {
428 static Icmp icmpv6 (AF_INET6);
429 return icmpv6;
430 }
431
436 constexpr int family () const noexcept
437 {
438 return _family;
439 }
440
445 constexpr int type () const noexcept
446 {
447 return SOCK_RAW;
448 }
449
454 constexpr int protocol () const noexcept
455 {
456 if (family () == AF_INET6)
457 {
458 return int (IPPROTO_ICMPV6);
459 }
460
461 return IPPROTO_ICMP;
462 }
463
464 private:
466 int _family;
467 };
468
475 constexpr bool operator== (const Icmp& a, const Icmp& b) noexcept
476 {
477 return a.family () == b.family ();
478 }
479
486 constexpr bool operator!= (const Icmp& a, const Icmp& b) noexcept
487 {
488 return !(a == b);
489 }
490
494 class Tcp
495 {
496 public:
501
506 constexpr Tcp (int family = AF_INET) noexcept
507 : _family (family)
508 {
509 }
510
515 static inline Tcp& v4 () noexcept
516 {
517 static Tcp tcpv4 (AF_INET);
518 return tcpv4;
519 }
520
525 static inline Tcp& v6 () noexcept
526 {
527 static Tcp tcpv6 (AF_INET6);
528 return tcpv6;
529 }
530
535 constexpr int family () const noexcept
536 {
537 return _family;
538 }
539
544 constexpr int type () const noexcept
545 {
546 return SOCK_STREAM;
547 }
548
553 constexpr int protocol () const noexcept
554 {
555 return IPPROTO_TCP;
556 }
557
558 private:
560 int _family;
561 };
562
569 constexpr bool operator== (const Tcp& a, const Tcp& b) noexcept
570 {
571 return a.family () == b.family ();
572 }
573
580 constexpr bool operator!= (const Tcp& a, const Tcp& b) noexcept
581 {
582 return !(a == b);
583 }
584
588 class Tls
589 {
590 public:
595
600 constexpr Tls (int family = AF_INET) noexcept
601 : _family (family)
602 {
603 }
604
609 static inline Tls& v4 () noexcept
610 {
611 static Tls tlsv4 (AF_INET);
612 return tlsv4;
613 }
614
619 static inline Tls& v6 () noexcept
620 {
621 static Tls tlsv6 (AF_INET6);
622 return tlsv6;
623 }
624
629 constexpr int family () const noexcept
630 {
631 return _family;
632 }
633
638 constexpr int type () const noexcept
639 {
640 return SOCK_STREAM;
641 }
642
647 constexpr int protocol () const noexcept
648 {
649 return IPPROTO_TCP;
650 }
651
652 private:
654 int _family;
655 };
656
663 constexpr bool operator== (const Tls& a, const Tls& b) noexcept
664 {
665 return a.family () == b.family ();
666 }
667
674 constexpr bool operator!= (const Tls& a, const Tls& b) noexcept
675 {
676 return !(a == b);
677 }
678
682 class Dns
683 {
684 public:
688
693 constexpr Dns (int family = AF_INET) noexcept
694 : _family (family)
695 {
696 }
697
702 static inline Dns& v4 () noexcept
703 {
704 static Dns dnsv4 (AF_INET);
705 return dnsv4;
706 }
707
712 static inline Dns& v6 () noexcept
713 {
714 static Dns dnsv6 (AF_INET6);
715 return dnsv6;
716 }
717
722 constexpr int family () const noexcept
723 {
724 return _family;
725 }
726
731 constexpr int type () const noexcept
732 {
733 return SOCK_DGRAM;
734 }
735
740 constexpr int protocol () const noexcept
741 {
742 return IPPROTO_UDP;
743 }
744
746 static constexpr uint16_t defaultPort = 53;
747
749 static constexpr size_t maxMsgSize = 8192;
750
751 private:
753 int _family;
754 };
755
762 constexpr bool operator== (const Dns& a, const Dns& b) noexcept
763 {
764 return a.family () == b.family ();
765 }
766
773 constexpr bool operator!= (const Dns& a, const Dns& b) noexcept
774 {
775 return !(a == b);
776 }
777
781 class Dot
782 {
783 public:
787
792 constexpr Dot (int family = AF_INET) noexcept
793 : _family (family)
794 {
795 }
796
801 static inline Dot& v4 () noexcept
802 {
803 static Dot dotv4 (AF_INET);
804 return dotv4;
805 }
806
811 static inline Dot& v6 () noexcept
812 {
813 static Dot dotv6 (AF_INET6);
814 return dotv6;
815 }
816
821 constexpr int family () const noexcept
822 {
823 return _family;
824 }
825
830 constexpr int type () const noexcept
831 {
832 return SOCK_STREAM;
833 }
834
839 constexpr int protocol () const noexcept
840 {
841 return IPPROTO_TCP;
842 }
843
845 static constexpr uint16_t defaultPort = 853;
846
848 static constexpr size_t maxMsgSize = 16384;
849
850 private:
852 int _family;
853 };
854
861 constexpr bool operator== (const Dot& a, const Dot& b) noexcept
862 {
863 return a.family () == b.family ();
864 }
865
872 constexpr bool operator!= (const Dot& a, const Dot& b) noexcept
873 {
874 return !(a == b);
875 }
876
880 class Http
881 {
882 public:
890
895 constexpr Http (int family = AF_INET) noexcept
896 : _family (family)
897 {
898 }
899
904 static inline Http& v4 () noexcept
905 {
906 static Http httpv4 (AF_INET);
907 return httpv4;
908 }
909
914 static inline Http& v6 () noexcept
915 {
916 static Http httpv6 (AF_INET6);
917 return httpv6;
918 }
919
924 constexpr int family () const noexcept
925 {
926 return _family;
927 }
928
933 constexpr int type () const noexcept
934 {
935 return SOCK_STREAM;
936 }
937
942 constexpr int protocol () const noexcept
943 {
944 return IPPROTO_TCP;
945 }
946
947 private:
949 int _family;
950 };
951
958 constexpr bool operator== (const Http& a, const Http& b) noexcept
959 {
960 return a.family () == b.family ();
961 }
962
969 constexpr bool operator!= (const Http& a, const Http& b) noexcept
970 {
971 return !(a == b);
972 }
973
977 class Https
978 {
979 public:
987
992 constexpr Https (int family = AF_INET) noexcept
993 : _family (family)
994 {
995 }
996
1001 static inline Https& v4 () noexcept
1002 {
1003 static Https httpsv4 (AF_INET);
1004 return httpsv4;
1005 }
1006
1011 static inline Https& v6 () noexcept
1012 {
1013 static Https httpsv6 (AF_INET6);
1014 return httpsv6;
1015 }
1016
1021 constexpr int family () const noexcept
1022 {
1023 return _family;
1024 }
1025
1030 constexpr int type () const noexcept
1031 {
1032 return SOCK_STREAM;
1033 }
1034
1039 constexpr int protocol () const noexcept
1040 {
1041 return IPPROTO_TCP;
1042 }
1043
1044 private:
1046 int _family;
1047 };
1048
1055 constexpr bool operator== (const Https& a, const Https& b) noexcept
1056 {
1057 return a.family () == b.family ();
1058 }
1059
1066 constexpr bool operator!= (const Https& a, const Https& b) noexcept
1067 {
1068 return !(a == b);
1069 }
1070
1074 class Smtp
1075 {
1076 public:
1081
1086 constexpr Smtp (int family = AF_INET) noexcept
1087 : _family (family)
1088 {
1089 }
1090
1095 static inline Smtp& v4 () noexcept
1096 {
1097 static Smtp smtpv4 (AF_INET);
1098 return smtpv4;
1099 }
1100
1105 static inline Smtp& v6 () noexcept
1106 {
1107 static Smtp smtpv6 (AF_INET6);
1108 return smtpv6;
1109 }
1110
1115 constexpr int family () const noexcept
1116 {
1117 return _family;
1118 }
1119
1124 constexpr int type () const noexcept
1125 {
1126 return SOCK_STREAM;
1127 }
1128
1133 constexpr int protocol () const noexcept
1134 {
1135 return IPPROTO_TCP;
1136 }
1137
1138 private:
1140 int _family;
1141 };
1142
1149 constexpr bool operator== (const Smtp& a, const Smtp& b) noexcept
1150 {
1151 return a.family () == b.family ();
1152 }
1153
1160 constexpr bool operator!= (const Smtp& a, const Smtp& b) noexcept
1161 {
1162 return !(a == b);
1163 }
1164
1168 class Smtps
1169 {
1170 public:
1175
1180 constexpr Smtps (int family = AF_INET) noexcept
1181 : _family (family)
1182 {
1183 }
1184
1189 static inline Smtps& v4 () noexcept
1190 {
1191 static Smtps smtpsv4 (AF_INET);
1192 return smtpsv4;
1193 }
1194
1199 static inline Smtps& v6 () noexcept
1200 {
1201 static Smtps smtpsv6 (AF_INET6);
1202 return smtpsv6;
1203 }
1204
1209 constexpr int family () const noexcept
1210 {
1211 return _family;
1212 }
1213
1218 constexpr int type () const noexcept
1219 {
1220 return SOCK_STREAM;
1221 }
1222
1227 constexpr int protocol () const noexcept
1228 {
1229 return IPPROTO_TCP;
1230 }
1231
1232 private:
1234 int _family;
1235 };
1236
1243 constexpr bool operator== (const Smtps& a, const Smtps& b) noexcept
1244 {
1245 return a.family () == b.family ();
1246 }
1247
1254 constexpr bool operator!= (const Smtps& a, const Smtps& b) noexcept
1255 {
1256 return !(a == b);
1257 }
1258}
1259
1260#endif
basic DNS resolver over datagram socket.
Definition resolver.hpp:51
basic datagram socket class.
Definition socket.hpp:645
basic HTTP client.
Definition httpclient.hpp:46
basic HTTPS client.
Definition httpclient.hpp:488
basic HTTPS server.
Definition httpserver.hpp:979
basic HTTP server.
Definition httpserver.hpp:644
basic HTTP worker.
Definition httpserver.hpp:81
basic internet endpoint class.
Definition endpoint.hpp:670
basic link layer endpoint class.
Definition endpoint.hpp:498
basic netlink endpoint class.
Definition endpoint.hpp:266
basic SMTP client.
Definition smtpclient.hpp:41
Basic SMTPS client.
Definition smtpclient.hpp:650
socket stream class.
Definition socketstream.hpp:329
basic socket class.
Definition socket.hpp:60
basic stream acceptor class.
Definition protocol.hpp:52
basic stream socket class.
Definition socket.hpp:1142
basic TLS acceptor class.
Definition protocol.hpp:54
basic DNS resolver over TLS socket (DNS over TLS).
Definition resolver.hpp:1033
basic TLS socket class.
Definition socket.hpp:1552
TLS stream class.
Definition socketstream.hpp:513
basic unix endpoint class.
Definition endpoint.hpp:98
DNS over UDP protocol class.
Definition protocol.hpp:683
static constexpr size_t maxMsgSize
maximum DNS message size.
Definition protocol.hpp:749
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:722
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:731
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:740
static Dns & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:712
constexpr Dns(int family=AF_INET) noexcept
construct the DNS protocol instance.
Definition protocol.hpp:693
static Dns & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:702
static constexpr uint16_t defaultPort
default DNS port.
Definition protocol.hpp:746
DNS over TLS protocol class.
Definition protocol.hpp:782
static constexpr uint16_t defaultPort
default DoT port.
Definition protocol.hpp:845
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:839
static constexpr size_t maxMsgSize
maximum DoT message size.
Definition protocol.hpp:848
static Dot & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:801
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:830
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:821
static Dot & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:811
constexpr Dot(int family=AF_INET) noexcept
construct the DoT protocol instance.
Definition protocol.hpp:792
HTTP protocol class.
Definition protocol.hpp:881
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:942
constexpr Http(int family=AF_INET) noexcept
create the HTTP protocol instance.
Definition protocol.hpp:895
static Http & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:904
static Http & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:914
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:933
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:924
HTTPS protocol class.
Definition protocol.hpp:978
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:1039
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:1021
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:1030
static Https & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:1011
static Https & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:1001
constexpr Https(int family=AF_INET) noexcept
create the HTTPS protocol instance.
Definition protocol.hpp:992
ICMP protocol class.
Definition protocol.hpp:398
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:436
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:454
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:445
static Icmp & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:426
static Icmp & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:416
constexpr Icmp(int family=AF_INET) noexcept
create the icmp protocol instance.
Definition protocol.hpp:407
RAW protocol class.
Definition protocol.hpp:260
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:283
constexpr Raw() noexcept=default
default constructor.
constexpr int family() const noexcept
get the protocol ip address family.
Definition protocol.hpp:274
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:292
SMTP protocol class.
Definition protocol.hpp:1075
static Smtp & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:1095
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:1133
static Smtp & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:1105
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:1115
constexpr Smtp(int family=AF_INET) noexcept
create the SMTP protocol instance.
Definition protocol.hpp:1086
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:1124
SMTPS protocol class.
Definition protocol.hpp:1169
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:1227
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:1218
constexpr Smtps(int family=AF_INET) noexcept
create the SMTPS protocol instance.
Definition protocol.hpp:1180
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:1209
static Smtps & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:1199
static Smtps & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:1189
TCP protocol class.
Definition protocol.hpp:495
static Tcp & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:525
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:544
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:535
constexpr Tcp(int family=AF_INET) noexcept
create the tcp protocol instance.
Definition protocol.hpp:506
static Tcp & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:515
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:553
SSL/TLS protocol class.
Definition protocol.hpp:589
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:647
static Tls & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:619
static Tls & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:609
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:629
constexpr Tls(int family=AF_INET) noexcept
create the tcp protocol instance.
Definition protocol.hpp:600
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:638
UDP protocol class.
Definition protocol.hpp:306
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:353
static Udp & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:334
static Udp & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:324
constexpr Udp(int family=AF_INET) noexcept
construct the udp protocol instance.
Definition protocol.hpp:315
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:344
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:362
unix datagram protocol class.
Definition protocol.hpp:82
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:105
constexpr UnixDgram() noexcept=default
construct the unix datagram protocol instance by default.
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:114
constexpr int family() const noexcept
get the protocol ip address family.
Definition protocol.hpp:96
unix stream protocol class.
Definition protocol.hpp:124
constexpr UnixStream() noexcept=default
construct the unix stream protocol instance by default.
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:149
constexpr int family() const noexcept
get the protocol ip address family.
Definition protocol.hpp:140
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:158
Definition acceptor.hpp:32
bool operator!=(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoints are not equal.
Definition endpoint.hpp:195
bool operator==(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoints are equal.
Definition endpoint.hpp:183