aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_nim/gnunet_cadet_service.nim
blob: a66d57e9648f8c64351c798adbb521f6b8475750 (plain) (blame)
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
 {.deadCodeElim: on.}
when defined(windows):
  const
    libname* = "libgnunetcadet.dll"
elif defined(macosx):
  const
    libname* = "libgnunetcadet.dylib"
else:
  const
    libname* = "libgnunetcadet.so"

import
  gnunet_types, gnunet_mq_lib, gnunet_crypto_lib, gnunet_configuration_lib


const
  GNUNET_CADET_VERSION* = 0x00000005


type
  GNUNET_CADET_Handle* {.bycopy.} = object

type
  GNUNET_CADET_Channel* {.bycopy.} = object

type
  GNUNET_CADET_Port* {.bycopy.} = object

type
  GNUNET_CADET_ConnectEventHandler* = proc (cls: pointer;
      channel: ptr GNUNET_CADET_Channel; source: ptr GNUNET_PeerIdentity): pointer {.
      cdecl.}


type
  GNUNET_CADET_DisconnectEventHandler* = proc (cls: pointer;
      channel: ptr GNUNET_CADET_Channel) {.cdecl.}


type
  GNUNET_CADET_WindowSizeEventHandler* = proc (cls: pointer;
      channel: ptr GNUNET_CADET_Channel; window_size: cint) {.cdecl.}


proc GNUNET_CADET_connect*(cfg: ptr GNUNET_CONFIGURATION_Handle): ptr GNUNET_CADET_Handle {.
    cdecl, importc: "GNUNET_CADET_connect", dynlib: libname.}

proc GNUNET_CADET_disconnect*(handle: ptr GNUNET_CADET_Handle) {.cdecl,
    importc: "GNUNET_CADET_disconnect", dynlib: libname.}

proc GNUNET_CADET_open_port*(h: ptr GNUNET_CADET_Handle; port: ptr GNUNET_HashCode;
                            connects: GNUNET_CADET_ConnectEventHandler;
                            connects_cls: pointer; window_changes: GNUNET_CADET_WindowSizeEventHandler;
                            disconnects: GNUNET_CADET_DisconnectEventHandler;
                            handlers: ptr GNUNET_MQ_MessageHandler): ptr GNUNET_CADET_Port {.
    cdecl, importc: "GNUNET_CADET_open_port", dynlib: libname.}

proc GNUNET_CADET_close_port*(p: ptr GNUNET_CADET_Port) {.cdecl,
    importc: "GNUNET_CADET_close_port", dynlib: libname.}

proc GNUNET_CADET_channel_create*(h: ptr GNUNET_CADET_Handle; channel_cls: pointer;
                                 destination: ptr GNUNET_PeerIdentity;
                                 port: ptr GNUNET_HashCode;
    window_changes: GNUNET_CADET_WindowSizeEventHandler; disconnects: GNUNET_CADET_DisconnectEventHandler;
                                 handlers: ptr GNUNET_MQ_MessageHandler): ptr GNUNET_CADET_Channel {.
    cdecl, importc: "GNUNET_CADET_channel_create", dynlib: libname.}

proc GNUNET_CADET_channel_destroy*(channel: ptr GNUNET_CADET_Channel) {.cdecl,
    importc: "GNUNET_CADET_channel_destroy", dynlib: libname.}

proc GNUNET_CADET_get_mq*(channel: ptr GNUNET_CADET_Channel): ptr GNUNET_MQ_Handle {.
    cdecl, importc: "GNUNET_CADET_get_mq", dynlib: libname.}

proc GNUNET_CADET_receive_done*(channel: ptr GNUNET_CADET_Channel) {.cdecl,
    importc: "GNUNET_CADET_receive_done", dynlib: libname.}

proc GC_u2h*(port: uint32): ptr GNUNET_HashCode {.cdecl, importc: "GC_u2h",
    dynlib: libname.}

type
  GNUNET_CADET_ChannelInfo* {.bycopy.} = object {.union.}
    yes_no*: cint
    peer*: GNUNET_PeerIdentity



type
  GNUNET_CADET_PeersCB* = proc (cls: pointer; peer: ptr GNUNET_PeerIdentity;
                             tunnel: cint; n_paths: cuint; best_path: cuint) {.cdecl.}


type
  GNUNET_CADET_PeerCB* = proc (cls: pointer; peer: ptr GNUNET_PeerIdentity;
                            tunnel: cint; neighbor: cint; n_paths: cuint;
                            paths: ptr GNUNET_PeerIdentity; offset: cint;
                            finished_with_paths: cint) {.cdecl.}


proc GNUNET_CADET_get_peers*(h: ptr GNUNET_CADET_Handle;
                            callback: GNUNET_CADET_PeersCB; callback_cls: pointer): cint {.
    cdecl, importc: "GNUNET_CADET_get_peers", dynlib: libname.}

proc GNUNET_CADET_get_peers_cancel*(h: ptr GNUNET_CADET_Handle): pointer {.cdecl,
    importc: "GNUNET_CADET_get_peers_cancel", dynlib: libname.}

proc GNUNET_CADET_get_peer*(h: ptr GNUNET_CADET_Handle; id: ptr GNUNET_PeerIdentity;
                           callback: GNUNET_CADET_PeerCB; callback_cls: pointer): cint {.
    cdecl, importc: "GNUNET_CADET_get_peer", dynlib: libname.}