1 /**
2 DTLS packet peer.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.packetpeerdtls;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.classdb;
24 import godot.packetpeer;
25 import godot.reference;
26 import godot.packetpeerudp;
27 import godot.x509certificate;
28 /**
29 DTLS packet peer.
30 
31 This class represents a DTLS peer connection. It can be used to connect to a DTLS server, and is returned by $(D DTLSServer.takeConnection).
32 $(B Warning:) SSL/TLS certificate revocation and certificate pinning are currently not supported. Revoked certificates are accepted as long as they are otherwise valid. If this is a concern, you may want to use automatically managed certificates with a short validity period.
33 */
34 @GodotBaseClass struct PacketPeerDTLS
35 {
36 	package(godot) enum string _GODOT_internal_name = "PacketPeerDTLS";
37 public:
38 @nogc nothrow:
39 	union { /** */ godot_object _godot_object; /** */ PacketPeer _GODOT_base; }
40 	alias _GODOT_base this;
41 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
42 	package(godot) __gshared bool _classBindingInitialized = false;
43 	package(godot) static struct GDNativeClassBinding
44 	{
45 		__gshared:
46 		@GodotName("connect_to_peer") GodotMethod!(GodotError, PacketPeerUDP, bool, String, X509Certificate) connectToPeer;
47 		@GodotName("disconnect_from_peer") GodotMethod!(void) disconnectFromPeer;
48 		@GodotName("get_status") GodotMethod!(PacketPeerDTLS.Status) getStatus;
49 		@GodotName("poll") GodotMethod!(void) poll;
50 	}
51 	/// 
52 	pragma(inline, true) bool opEquals(in PacketPeerDTLS other) const
53 	{ return _godot_object.ptr is other._godot_object.ptr; }
54 	/// 
55 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
56 	{ _godot_object.ptr = n; return null; }
57 	/// 
58 	pragma(inline, true) bool opEquals(typeof(null) n) const
59 	{ return _godot_object.ptr is n; }
60 	/// 
61 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
62 	mixin baseCasts;
63 	/// Construct a new instance of PacketPeerDTLS.
64 	/// Note: use `memnew!PacketPeerDTLS` instead.
65 	static PacketPeerDTLS _new()
66 	{
67 		static godot_class_constructor constructor;
68 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PacketPeerDTLS");
69 		if(constructor is null) return typeof(this).init;
70 		return cast(PacketPeerDTLS)(constructor());
71 	}
72 	@disable new(size_t s);
73 	/// 
74 	enum Status : int
75 	{
76 		/**
77 		A status representing a $(D PacketPeerDTLS) that is disconnected.
78 		*/
79 		statusDisconnected = 0,
80 		/**
81 		A status representing a $(D PacketPeerDTLS) that is currently performing the handshake with a remote peer.
82 		*/
83 		statusHandshaking = 1,
84 		/**
85 		A status representing a $(D PacketPeerDTLS) that is connected to a remote peer.
86 		*/
87 		statusConnected = 2,
88 		/**
89 		A status representing a $(D PacketPeerDTLS) in a generic error state.
90 		*/
91 		statusError = 3,
92 		/**
93 		An error status that shows a mismatch in the DTLS certificate domain presented by the host and the domain requested for validation.
94 		*/
95 		statusErrorHostnameMismatch = 4,
96 	}
97 	/// 
98 	enum Constants : int
99 	{
100 		statusDisconnected = 0,
101 		statusHandshaking = 1,
102 		statusConnected = 2,
103 		statusError = 3,
104 		statusErrorHostnameMismatch = 4,
105 	}
106 	/**
107 	Connects a `peer` beginning the DTLS handshake using the underlying $(D PacketPeerUDP) which must be connected (see $(D PacketPeerUDP.connectToHost)). If `validate_certs` is `true`, $(D PacketPeerDTLS) will validate that the certificate presented by the remote peer and match it with the `for_hostname` argument. You can specify a custom $(D X509Certificate) to use for validation via the `valid_certificate` argument.
108 	*/
109 	GodotError connectToPeer(PacketPeerUDP packet_peer, in bool validate_certs = true, in String for_hostname = gs!"", X509Certificate valid_certificate = X509Certificate.init)
110 	{
111 		checkClassBinding!(typeof(this))();
112 		return ptrcall!(GodotError)(GDNativeClassBinding.connectToPeer, _godot_object, packet_peer, validate_certs, for_hostname, valid_certificate);
113 	}
114 	/**
115 	Disconnects this peer, terminating the DTLS session.
116 	*/
117 	void disconnectFromPeer()
118 	{
119 		checkClassBinding!(typeof(this))();
120 		ptrcall!(void)(GDNativeClassBinding.disconnectFromPeer, _godot_object);
121 	}
122 	/**
123 	Returns the status of the connection. See $(D status) for values.
124 	*/
125 	PacketPeerDTLS.Status getStatus() const
126 	{
127 		checkClassBinding!(typeof(this))();
128 		return ptrcall!(PacketPeerDTLS.Status)(GDNativeClassBinding.getStatus, _godot_object);
129 	}
130 	/**
131 	Poll the connection to check for incoming packets. Call this frequently to update the status and keep the connection working.
132 	*/
133 	void poll()
134 	{
135 		checkClassBinding!(typeof(this))();
136 		ptrcall!(void)(GDNativeClassBinding.poll, _godot_object);
137 	}
138 }