Initial checkin
[ldk-swift-linux] / LDKSwift / Sources / LDKSwift / structs / PeerManager.swift
1 import LDKCHeaders
2
3 public class PeerManager {
4
5     public internal(set) var cOpaqueStruct: LDKPeerManager?;
6
7         /* DEFAULT_CONSTRUCTOR_START */
8     public init(message_handler: MessageHandler, our_node_secret: [UInt8], ephemeral_random_data: [UInt8], logger: Logger) {
9         
10         self.cOpaqueStruct = withUnsafePointer(to: Bindings.array_to_tuple32(array: ephemeral_random_data)) { (ephemeral_random_dataPointer: UnsafePointer<(UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8)>) in
11 PeerManager_new(message_handler.cOpaqueStruct!, Bindings.new_LDKSecretKey(array: our_node_secret), ephemeral_random_dataPointer, logger.cOpaqueStruct!)
12 }
13     }
14     /* DEFAULT_CONSTRUCTOR_END */
15
16     public init(pointer: LDKPeerManager){
17                 self.cOpaqueStruct = pointer
18         }
19
20     /* STRUCT_METHODS_START */
21
22     public func get_peer_node_ids() -> [[UInt8]] {
23         
24         return Bindings.LDKCVec_PublicKeyZ_to_array(nativeType: withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKPeerManager>) in
25 PeerManager_get_peer_node_ids(this_argPointer)
26 });
27     }
28
29     public func new_outbound_connection(their_node_id: [UInt8], descriptor: SocketDescriptor) -> Result_CVec_u8ZPeerHandleErrorZ {
30         
31         return Result_CVec_u8ZPeerHandleErrorZ(pointer: withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKPeerManager>) in
32 PeerManager_new_outbound_connection(this_argPointer, Bindings.new_LDKPublicKey(array: their_node_id), descriptor.cOpaqueStruct!)
33 });
34     }
35
36     public func new_inbound_connection(descriptor: SocketDescriptor) -> Result_NonePeerHandleErrorZ {
37         
38         return Result_NonePeerHandleErrorZ(pointer: withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKPeerManager>) in
39 PeerManager_new_inbound_connection(this_argPointer, descriptor.cOpaqueStruct!)
40 });
41     }
42
43     public func write_buffer_space_avail(descriptor: SocketDescriptor) -> Result_NonePeerHandleErrorZ {
44         
45                                                         let descriptorPointer = UnsafeMutablePointer<LDKSocketDescriptor>.allocate(capacity: 1)
46                                                         descriptorPointer.initialize(to: descriptor.cOpaqueStruct!)
47                                                 
48         return Result_NonePeerHandleErrorZ(pointer: withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKPeerManager>) in
49 PeerManager_write_buffer_space_avail(this_argPointer, descriptorPointer)
50 });
51     }
52
53     public func read_event(peer_descriptor: SocketDescriptor, data: [UInt8]) -> Result_boolPeerHandleErrorZ {
54         
55                                                         let peer_descriptorPointer = UnsafeMutablePointer<LDKSocketDescriptor>.allocate(capacity: 1)
56                                                         peer_descriptorPointer.initialize(to: peer_descriptor.cOpaqueStruct!)
57                                                 
58         return Result_boolPeerHandleErrorZ(pointer: withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKPeerManager>) in
59 PeerManager_read_event(this_argPointer, peer_descriptorPointer, Bindings.new_LDKu8slice(array: data))
60 });
61     }
62
63     public func process_events() -> Void {
64         
65         return withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKPeerManager>) in
66 PeerManager_process_events(this_argPointer)
67 };
68     }
69
70     public func socket_disconnected(descriptor: SocketDescriptor) -> Void {
71         
72         return withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKPeerManager>) in
73 withUnsafePointer(to: descriptor.cOpaqueStruct!) { (descriptorPointer: UnsafePointer<LDKSocketDescriptor>) in
74 PeerManager_socket_disconnected(this_argPointer, descriptorPointer)
75 }
76 };
77     }
78
79     public func disconnect_by_node_id(node_id: [UInt8], no_connection_possible: Bool) -> Void {
80         
81         return withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKPeerManager>) in
82 PeerManager_disconnect_by_node_id(this_argPointer, Bindings.new_LDKPublicKey(array: node_id), no_connection_possible)
83 };
84     }
85
86     public func timer_tick_occurred() -> Void {
87         
88         return withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKPeerManager>) in
89 PeerManager_timer_tick_occurred(this_argPointer)
90 };
91     }
92
93                                 
94         deinit {
95                                         if self.cOpaqueStruct?.is_owned == false {
96
97                                         
98                                         
99                 PeerManager_free(self.cOpaqueStruct!)
100                                         
101 }
102                                 
103         }
104                         
105     /* STRUCT_METHODS_END */
106
107 }