ipfs-node 0.1.12rc1__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ipfs_node/__init__.py +4 -0
- ipfs_node/ipfs_files.py +233 -0
- ipfs_node/ipfs_node.py +230 -0
- ipfs_node/ipfs_peers.py +71 -0
- ipfs_node/ipfs_pubsub.py +474 -0
- ipfs_node/ipfs_tunnels.py +263 -0
- ipfs_node/utils/__init__.py +3 -0
- ipfs_node/utils/cid_utils.py +55 -0
- ipfs_node/utils/peer_utils.py +62 -0
- ipfs_node-0.1.12rc1.dist-info/METADATA +194 -0
- ipfs_node-0.1.12rc1.dist-info/RECORD +20 -0
- ipfs_node-0.1.12rc1.dist-info/WHEEL +5 -0
- ipfs_node-0.1.12rc1.dist-info/licenses/LICENSE +18 -0
- ipfs_node-0.1.12rc1.dist-info/licenses/LICENSE-CC0 +121 -0
- ipfs_node-0.1.12rc1.dist-info/top_level.txt +2 -0
- libkubo/__init__.py +1 -0
- libkubo/libkubo_linux_x86_64.h +237 -0
- libkubo/libkubo_loader.py +88 -0
- libkubo/libkubo_windows_x86_64.dll +0 -0
- libkubo/libkubo_windows_x86_64.h +237 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Creative Commons Legal Code
|
|
2
|
+
|
|
3
|
+
CC0 1.0 Universal
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
libkubo/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .libkubo_loader import libkubo, c_str, from_c_str, ffi, c_bool
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/* Code generated by cmd/cgo; DO NOT EDIT. */
|
|
2
|
+
|
|
3
|
+
/* package github.com/emendir/py_ipfs_node/libkubo */
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
#line 1 "cgo-builtin-export-prolog"
|
|
7
|
+
|
|
8
|
+
#include <stddef.h>
|
|
9
|
+
|
|
10
|
+
#ifndef GO_CGO_EXPORT_PROLOGUE_H
|
|
11
|
+
#define GO_CGO_EXPORT_PROLOGUE_H
|
|
12
|
+
|
|
13
|
+
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
|
14
|
+
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
/* Start of preamble from import "C" comments. */
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
#line 3 "files.go"
|
|
23
|
+
#include <stdlib.h>
|
|
24
|
+
#include <stdbool.h>
|
|
25
|
+
|
|
26
|
+
#line 1 "cgo-generated-wrapper"
|
|
27
|
+
|
|
28
|
+
#line 3 "p2p.go"
|
|
29
|
+
|
|
30
|
+
#include <stdlib.h>
|
|
31
|
+
#include <stdbool.h>
|
|
32
|
+
|
|
33
|
+
#line 1 "cgo-generated-wrapper"
|
|
34
|
+
|
|
35
|
+
#line 3 "peers.go"
|
|
36
|
+
#include <stdlib.h>
|
|
37
|
+
|
|
38
|
+
#line 1 "cgo-generated-wrapper"
|
|
39
|
+
|
|
40
|
+
#line 3 "pubsub.go"
|
|
41
|
+
#include <stdlib.h>
|
|
42
|
+
|
|
43
|
+
#line 1 "cgo-generated-wrapper"
|
|
44
|
+
|
|
45
|
+
#line 3 "repo.go"
|
|
46
|
+
#include <stdlib.h>
|
|
47
|
+
|
|
48
|
+
#line 1 "cgo-generated-wrapper"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/* End of preamble from import "C" comments. */
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/* Start of boilerplate cgo prologue. */
|
|
55
|
+
#line 1 "cgo-gcc-export-header-prolog"
|
|
56
|
+
|
|
57
|
+
#ifndef GO_CGO_PROLOGUE_H
|
|
58
|
+
#define GO_CGO_PROLOGUE_H
|
|
59
|
+
|
|
60
|
+
typedef signed char GoInt8;
|
|
61
|
+
typedef unsigned char GoUint8;
|
|
62
|
+
typedef short GoInt16;
|
|
63
|
+
typedef unsigned short GoUint16;
|
|
64
|
+
typedef int GoInt32;
|
|
65
|
+
typedef unsigned int GoUint32;
|
|
66
|
+
typedef long long GoInt64;
|
|
67
|
+
typedef unsigned long long GoUint64;
|
|
68
|
+
typedef GoInt64 GoInt;
|
|
69
|
+
typedef GoUint64 GoUint;
|
|
70
|
+
typedef size_t GoUintptr;
|
|
71
|
+
typedef float GoFloat32;
|
|
72
|
+
typedef double GoFloat64;
|
|
73
|
+
#ifdef _MSC_VER
|
|
74
|
+
#include <complex.h>
|
|
75
|
+
typedef _Fcomplex GoComplex64;
|
|
76
|
+
typedef _Dcomplex GoComplex128;
|
|
77
|
+
#else
|
|
78
|
+
typedef float _Complex GoComplex64;
|
|
79
|
+
typedef double _Complex GoComplex128;
|
|
80
|
+
#endif
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
static assertion to make sure the file is being used on architecture
|
|
84
|
+
at least with matching size of GoInt.
|
|
85
|
+
*/
|
|
86
|
+
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
|
|
87
|
+
|
|
88
|
+
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
|
89
|
+
typedef _GoString_ GoString;
|
|
90
|
+
#endif
|
|
91
|
+
typedef void *GoMap;
|
|
92
|
+
typedef void *GoChan;
|
|
93
|
+
typedef struct { void *t; void *v; } GoInterface;
|
|
94
|
+
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
|
95
|
+
|
|
96
|
+
#endif
|
|
97
|
+
|
|
98
|
+
/* End of boilerplate cgo prologue. */
|
|
99
|
+
|
|
100
|
+
#ifdef __cplusplus
|
|
101
|
+
extern "C" {
|
|
102
|
+
#endif
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// AddFile adds a file to IPFS
|
|
106
|
+
//
|
|
107
|
+
extern char* AddFile(char* repoPath, char* filePath, _Bool onlyHash);
|
|
108
|
+
|
|
109
|
+
// FreeString is a no-op for now - we'll let Go's garbage collection handle the memory
|
|
110
|
+
//
|
|
111
|
+
extern void FreeString(char* str);
|
|
112
|
+
|
|
113
|
+
// Download retrieves a file or directory from IPFS
|
|
114
|
+
//
|
|
115
|
+
extern int Download(char* repoPath, char* cidStr, char* destPath);
|
|
116
|
+
|
|
117
|
+
// PinCID pins a CID to the IPFS node
|
|
118
|
+
//
|
|
119
|
+
extern int PinCID(char* repoPath, char* cidStr);
|
|
120
|
+
|
|
121
|
+
// UnpinCID unpins a CID from the IPFS node
|
|
122
|
+
//
|
|
123
|
+
extern int UnpinCID(char* repoPath, char* cidStr);
|
|
124
|
+
|
|
125
|
+
// ListPins returns a list of pinned CIDs
|
|
126
|
+
//
|
|
127
|
+
extern char* ListPins(char* repoPath);
|
|
128
|
+
|
|
129
|
+
// RemoveCID removes a pinned CID from IPFS (alias for UnpinCID for clarity)
|
|
130
|
+
//
|
|
131
|
+
extern int RemoveCID(char* repoPath, char* cidStr);
|
|
132
|
+
|
|
133
|
+
// P2PForward creates a libp2p stream mounting forwarding connection
|
|
134
|
+
//
|
|
135
|
+
extern int P2PForward(char* repoPath, char* proto, char* listenAddr, char* targetPeerID);
|
|
136
|
+
|
|
137
|
+
// P2PListen creates a libp2p service that listens for connections on the given protocol
|
|
138
|
+
//
|
|
139
|
+
extern int P2PListen(char* repoPath, char* proto, char* targetAddr);
|
|
140
|
+
|
|
141
|
+
// P2PClose closes p2p listener or stream
|
|
142
|
+
//
|
|
143
|
+
extern int P2PClose(char* repoPath, char* proto, char* listenAddr, char* targetAddr, _Bool _all, _Bool listeners, _Bool forwarders);
|
|
144
|
+
|
|
145
|
+
// P2PListListeners lists active p2p listeners
|
|
146
|
+
//
|
|
147
|
+
extern char* P2PListListeners(char* repoPath);
|
|
148
|
+
|
|
149
|
+
// P2PEnable ensures p2p functionality is enabled in the config
|
|
150
|
+
//
|
|
151
|
+
extern int P2PEnable(char* repoPath);
|
|
152
|
+
|
|
153
|
+
// P2PListForwards lists active p2p forwarding connections
|
|
154
|
+
//
|
|
155
|
+
extern char* P2PListForwards(char* repoPath);
|
|
156
|
+
|
|
157
|
+
// P2PCloseAllListeners closes all p2p listeners
|
|
158
|
+
//
|
|
159
|
+
extern int P2PCloseAllListeners(char* repoPath);
|
|
160
|
+
|
|
161
|
+
// P2PCloseAllForwards closes all p2p forwards
|
|
162
|
+
//
|
|
163
|
+
extern int P2PCloseAllForwards(char* repoPath);
|
|
164
|
+
|
|
165
|
+
// ConnectToPeer connects to a peer
|
|
166
|
+
//
|
|
167
|
+
extern int ConnectToPeer(char* repoPath, char* peerAddr);
|
|
168
|
+
|
|
169
|
+
// ListPeers connects to a peer
|
|
170
|
+
//
|
|
171
|
+
extern char* ListPeers(char* repoPath);
|
|
172
|
+
|
|
173
|
+
// ListPeers connects to a peer
|
|
174
|
+
//
|
|
175
|
+
extern char* ListPeersIDs(char* repoPath);
|
|
176
|
+
|
|
177
|
+
// FindPeer connects to a peer
|
|
178
|
+
//
|
|
179
|
+
extern char* FindPeer(char* repoPath, char* peerAddr, int timeOut);
|
|
180
|
+
|
|
181
|
+
// PubSubListTopics lists the topics the node is subscribed to
|
|
182
|
+
//
|
|
183
|
+
extern char* PubSubListTopics(char* repoPath);
|
|
184
|
+
|
|
185
|
+
// PubSubPublish publishes a message to a topic
|
|
186
|
+
//
|
|
187
|
+
extern int PubSubPublish(char* repoPath, char* topic, void* data, int dataLen);
|
|
188
|
+
|
|
189
|
+
// PubSubSubscribe subscribes to a topic
|
|
190
|
+
//
|
|
191
|
+
extern long long int PubSubSubscribe(char* repoPath, char* topic);
|
|
192
|
+
|
|
193
|
+
// PubSubNextMessage gets the next message from a subscription
|
|
194
|
+
//
|
|
195
|
+
extern char* PubSubNextMessage(long long int subID);
|
|
196
|
+
|
|
197
|
+
// PubSubUnsubscribe unsubscribes from a topic
|
|
198
|
+
//
|
|
199
|
+
extern int PubSubUnsubscribe(long long int subID);
|
|
200
|
+
|
|
201
|
+
// PubSubPeers lists peers participating in a topic
|
|
202
|
+
//
|
|
203
|
+
extern char* PubSubPeers(char* repoPath, char* topic);
|
|
204
|
+
|
|
205
|
+
// PubSubCloseRepoSubscriptions closes all active pubsub subscriptions for a specific repository
|
|
206
|
+
//
|
|
207
|
+
extern int PubSubCloseRepoSubscriptions(char* repoPath);
|
|
208
|
+
|
|
209
|
+
// PubSubCloseAllSubscriptions closes all active pubsub subscriptions across all repositories
|
|
210
|
+
//
|
|
211
|
+
extern int PubSubCloseAllSubscriptions();
|
|
212
|
+
|
|
213
|
+
// CreateRepo initializes a new IPFS repository
|
|
214
|
+
//
|
|
215
|
+
extern int CreateRepo(char* repoPath);
|
|
216
|
+
extern int RunNode(char* repoPath);
|
|
217
|
+
|
|
218
|
+
// PubSubEnable enables pubsub on an IPFS node configuration
|
|
219
|
+
//
|
|
220
|
+
extern int PubSubEnable(char* repoPath);
|
|
221
|
+
extern char* TestGetString();
|
|
222
|
+
|
|
223
|
+
// GetNodeID gets the ID of the IPFS node
|
|
224
|
+
//
|
|
225
|
+
extern char* GetNodeID(char* repoPath);
|
|
226
|
+
|
|
227
|
+
// GetNodeMultiAddrs gets the ID of the IPFS node
|
|
228
|
+
//
|
|
229
|
+
extern char* GetNodeMultiAddrs(char* repoPath);
|
|
230
|
+
|
|
231
|
+
// CleanupNode explicitly releases a node by path
|
|
232
|
+
//
|
|
233
|
+
extern int CleanupNode(char* repoPath);
|
|
234
|
+
|
|
235
|
+
#ifdef __cplusplus
|
|
236
|
+
}
|
|
237
|
+
#endif
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from cffi import FFI
|
|
3
|
+
import platform
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
ffi = FFI()
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def is_android() -> bool:
|
|
10
|
+
"""Check if OS is android."""
|
|
11
|
+
if "ANDROID_ROOT" in os.environ and "ANDROID_DATA" in os.environ:
|
|
12
|
+
return True
|
|
13
|
+
return (
|
|
14
|
+
"android" in platform.release().lower()
|
|
15
|
+
or "android" in platform.version().lower()
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
system = platform.system()
|
|
20
|
+
machine = platform.machine().lower()
|
|
21
|
+
|
|
22
|
+
if system == "Windows":
|
|
23
|
+
if machine in ("x86_64", "amd64"):
|
|
24
|
+
lib_name = "libkubo_windows_x86_64.dll"
|
|
25
|
+
# header_name = "libkubo_windows_x86_64.h"
|
|
26
|
+
# windows header causes problems, so parse linux header instead
|
|
27
|
+
header_name = "libkubo_linux_x86_64.h"
|
|
28
|
+
# elif machine in ("aarch64", "arm64"):
|
|
29
|
+
# lib_name = "libkubo_windows_arm64.dll"
|
|
30
|
+
# header_name = "libkubo_windows_arm64.h"
|
|
31
|
+
else:
|
|
32
|
+
raise RuntimeError(f"Unsupported Windows architecture: {machine}")
|
|
33
|
+
|
|
34
|
+
elif system == "Darwin":
|
|
35
|
+
lib_name = "libkubo.dylib"
|
|
36
|
+
header_name = "libkubo.h"
|
|
37
|
+
|
|
38
|
+
elif system == "Linux":
|
|
39
|
+
if is_android():
|
|
40
|
+
if machine in ("aarch64", "arm64"):
|
|
41
|
+
lib_name = "libkubo_android_arm64.so"
|
|
42
|
+
header_name = "libkubo_android_arm64.h"
|
|
43
|
+
else:
|
|
44
|
+
raise RuntimeError(f"Unsupported Android arch: {machine}")
|
|
45
|
+
else:
|
|
46
|
+
if machine in ("x86_64", "amd64"):
|
|
47
|
+
lib_name = "libkubo_linux_x86_64.so"
|
|
48
|
+
header_name = "libkubo_linux_x86_64.h"
|
|
49
|
+
elif machine in ("aarch64", "arm64"):
|
|
50
|
+
lib_name = "libkubo_linux_arm64.so"
|
|
51
|
+
header_name = "libkubo_linux_arm64.h"
|
|
52
|
+
elif machine.startswith("armv7") or machine == "armv7l":
|
|
53
|
+
lib_name = "libkubo_linux_armhf.so"
|
|
54
|
+
header_name = "libkubo_linux_armhf.h"
|
|
55
|
+
else:
|
|
56
|
+
raise RuntimeError(f"Unsupported Linux architecture: {machine}")
|
|
57
|
+
else:
|
|
58
|
+
raise RuntimeError(f"Unsupported platform: {system} {machine}")
|
|
59
|
+
|
|
60
|
+
print(lib_name)
|
|
61
|
+
print(header_name)
|
|
62
|
+
|
|
63
|
+
# Get the absolute path to the library
|
|
64
|
+
lib_path = str(Path(__file__).parent / lib_name)
|
|
65
|
+
header_path = str(Path(__file__).parent / header_name)
|
|
66
|
+
|
|
67
|
+
with open(header_path) as file:
|
|
68
|
+
lines = [line.strip() for line in file.readlines()]
|
|
69
|
+
func_declarations = [
|
|
70
|
+
line for line in lines if line.startswith("extern ") and line.endswith(";")
|
|
71
|
+
]
|
|
72
|
+
ffi.cdef("\n".join(func_declarations))
|
|
73
|
+
ffi.set_source("libkubo", None)
|
|
74
|
+
libkubo = ffi.dlopen(lib_path)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def c_str(data: str | bytes):
|
|
78
|
+
if isinstance(data, str):
|
|
79
|
+
data = data.encode()
|
|
80
|
+
return ffi.new("char[]", data)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def from_c_str(string_ptr):
|
|
84
|
+
return ffi.string(string_ptr).decode("utf-8")
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def c_bool(value: bool):
|
|
88
|
+
return ffi.new("bool *", value)[0]
|
|
Binary file
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/* Code generated by cmd/cgo; DO NOT EDIT. */
|
|
2
|
+
|
|
3
|
+
/* package github.com/emendir/py_ipfs_node/libkubo */
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
#line 1 "cgo-builtin-export-prolog"
|
|
7
|
+
|
|
8
|
+
#include <stddef.h>
|
|
9
|
+
|
|
10
|
+
#ifndef GO_CGO_EXPORT_PROLOGUE_H
|
|
11
|
+
#define GO_CGO_EXPORT_PROLOGUE_H
|
|
12
|
+
|
|
13
|
+
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
|
14
|
+
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
/* Start of preamble from import "C" comments. */
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
#line 3 "files.go"
|
|
23
|
+
#include <stdlib.h>
|
|
24
|
+
#include <stdbool.h>
|
|
25
|
+
|
|
26
|
+
#line 1 "cgo-generated-wrapper"
|
|
27
|
+
|
|
28
|
+
#line 3 "p2p.go"
|
|
29
|
+
|
|
30
|
+
#include <stdlib.h>
|
|
31
|
+
#include <stdbool.h>
|
|
32
|
+
|
|
33
|
+
#line 1 "cgo-generated-wrapper"
|
|
34
|
+
|
|
35
|
+
#line 3 "peers.go"
|
|
36
|
+
#include <stdlib.h>
|
|
37
|
+
|
|
38
|
+
#line 1 "cgo-generated-wrapper"
|
|
39
|
+
|
|
40
|
+
#line 3 "pubsub.go"
|
|
41
|
+
#include <stdlib.h>
|
|
42
|
+
|
|
43
|
+
#line 1 "cgo-generated-wrapper"
|
|
44
|
+
|
|
45
|
+
#line 3 "repo.go"
|
|
46
|
+
#include <stdlib.h>
|
|
47
|
+
|
|
48
|
+
#line 1 "cgo-generated-wrapper"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/* End of preamble from import "C" comments. */
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/* Start of boilerplate cgo prologue. */
|
|
55
|
+
#line 1 "cgo-gcc-export-header-prolog"
|
|
56
|
+
|
|
57
|
+
#ifndef GO_CGO_PROLOGUE_H
|
|
58
|
+
#define GO_CGO_PROLOGUE_H
|
|
59
|
+
|
|
60
|
+
typedef signed char GoInt8;
|
|
61
|
+
typedef unsigned char GoUint8;
|
|
62
|
+
typedef short GoInt16;
|
|
63
|
+
typedef unsigned short GoUint16;
|
|
64
|
+
typedef int GoInt32;
|
|
65
|
+
typedef unsigned int GoUint32;
|
|
66
|
+
typedef long long GoInt64;
|
|
67
|
+
typedef unsigned long long GoUint64;
|
|
68
|
+
typedef GoInt64 GoInt;
|
|
69
|
+
typedef GoUint64 GoUint;
|
|
70
|
+
typedef size_t GoUintptr;
|
|
71
|
+
typedef float GoFloat32;
|
|
72
|
+
typedef double GoFloat64;
|
|
73
|
+
#ifdef _MSC_VER
|
|
74
|
+
#include <complex.h>
|
|
75
|
+
typedef _Fcomplex GoComplex64;
|
|
76
|
+
typedef _Dcomplex GoComplex128;
|
|
77
|
+
#else
|
|
78
|
+
typedef float _Complex GoComplex64;
|
|
79
|
+
typedef double _Complex GoComplex128;
|
|
80
|
+
#endif
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
static assertion to make sure the file is being used on architecture
|
|
84
|
+
at least with matching size of GoInt.
|
|
85
|
+
*/
|
|
86
|
+
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
|
|
87
|
+
|
|
88
|
+
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
|
89
|
+
typedef _GoString_ GoString;
|
|
90
|
+
#endif
|
|
91
|
+
typedef void *GoMap;
|
|
92
|
+
typedef void *GoChan;
|
|
93
|
+
typedef struct { void *t; void *v; } GoInterface;
|
|
94
|
+
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
|
95
|
+
|
|
96
|
+
#endif
|
|
97
|
+
|
|
98
|
+
/* End of boilerplate cgo prologue. */
|
|
99
|
+
|
|
100
|
+
#ifdef __cplusplus
|
|
101
|
+
extern "C" {
|
|
102
|
+
#endif
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// AddFile adds a file to IPFS
|
|
106
|
+
//
|
|
107
|
+
extern __declspec(dllexport) char* AddFile(char* repoPath, char* filePath, _Bool onlyHash);
|
|
108
|
+
|
|
109
|
+
// FreeString is a no-op for now - we'll let Go's garbage collection handle the memory
|
|
110
|
+
//
|
|
111
|
+
extern __declspec(dllexport) void FreeString(char* str);
|
|
112
|
+
|
|
113
|
+
// Download retrieves a file or directory from IPFS
|
|
114
|
+
//
|
|
115
|
+
extern __declspec(dllexport) int Download(char* repoPath, char* cidStr, char* destPath);
|
|
116
|
+
|
|
117
|
+
// PinCID pins a CID to the IPFS node
|
|
118
|
+
//
|
|
119
|
+
extern __declspec(dllexport) int PinCID(char* repoPath, char* cidStr);
|
|
120
|
+
|
|
121
|
+
// UnpinCID unpins a CID from the IPFS node
|
|
122
|
+
//
|
|
123
|
+
extern __declspec(dllexport) int UnpinCID(char* repoPath, char* cidStr);
|
|
124
|
+
|
|
125
|
+
// ListPins returns a list of pinned CIDs
|
|
126
|
+
//
|
|
127
|
+
extern __declspec(dllexport) char* ListPins(char* repoPath);
|
|
128
|
+
|
|
129
|
+
// RemoveCID removes a pinned CID from IPFS (alias for UnpinCID for clarity)
|
|
130
|
+
//
|
|
131
|
+
extern __declspec(dllexport) int RemoveCID(char* repoPath, char* cidStr);
|
|
132
|
+
|
|
133
|
+
// P2PForward creates a libp2p stream mounting forwarding connection
|
|
134
|
+
//
|
|
135
|
+
extern __declspec(dllexport) int P2PForward(char* repoPath, char* proto, char* listenAddr, char* targetPeerID);
|
|
136
|
+
|
|
137
|
+
// P2PListen creates a libp2p service that listens for connections on the given protocol
|
|
138
|
+
//
|
|
139
|
+
extern __declspec(dllexport) int P2PListen(char* repoPath, char* proto, char* targetAddr);
|
|
140
|
+
|
|
141
|
+
// P2PClose closes p2p listener or stream
|
|
142
|
+
//
|
|
143
|
+
extern __declspec(dllexport) int P2PClose(char* repoPath, char* proto, char* listenAddr, char* targetAddr, _Bool _all, _Bool listeners, _Bool forwarders);
|
|
144
|
+
|
|
145
|
+
// P2PListListeners lists active p2p listeners
|
|
146
|
+
//
|
|
147
|
+
extern __declspec(dllexport) char* P2PListListeners(char* repoPath);
|
|
148
|
+
|
|
149
|
+
// P2PEnable ensures p2p functionality is enabled in the config
|
|
150
|
+
//
|
|
151
|
+
extern __declspec(dllexport) int P2PEnable(char* repoPath);
|
|
152
|
+
|
|
153
|
+
// P2PListForwards lists active p2p forwarding connections
|
|
154
|
+
//
|
|
155
|
+
extern __declspec(dllexport) char* P2PListForwards(char* repoPath);
|
|
156
|
+
|
|
157
|
+
// P2PCloseAllListeners closes all p2p listeners
|
|
158
|
+
//
|
|
159
|
+
extern __declspec(dllexport) int P2PCloseAllListeners(char* repoPath);
|
|
160
|
+
|
|
161
|
+
// P2PCloseAllForwards closes all p2p forwards
|
|
162
|
+
//
|
|
163
|
+
extern __declspec(dllexport) int P2PCloseAllForwards(char* repoPath);
|
|
164
|
+
|
|
165
|
+
// ConnectToPeer connects to a peer
|
|
166
|
+
//
|
|
167
|
+
extern __declspec(dllexport) int ConnectToPeer(char* repoPath, char* peerAddr);
|
|
168
|
+
|
|
169
|
+
// ListPeers connects to a peer
|
|
170
|
+
//
|
|
171
|
+
extern __declspec(dllexport) char* ListPeers(char* repoPath);
|
|
172
|
+
|
|
173
|
+
// ListPeers connects to a peer
|
|
174
|
+
//
|
|
175
|
+
extern __declspec(dllexport) char* ListPeersIDs(char* repoPath);
|
|
176
|
+
|
|
177
|
+
// FindPeer connects to a peer
|
|
178
|
+
//
|
|
179
|
+
extern __declspec(dllexport) char* FindPeer(char* repoPath, char* peerAddr, int timeOut);
|
|
180
|
+
|
|
181
|
+
// PubSubListTopics lists the topics the node is subscribed to
|
|
182
|
+
//
|
|
183
|
+
extern __declspec(dllexport) char* PubSubListTopics(char* repoPath);
|
|
184
|
+
|
|
185
|
+
// PubSubPublish publishes a message to a topic
|
|
186
|
+
//
|
|
187
|
+
extern __declspec(dllexport) int PubSubPublish(char* repoPath, char* topic, void* data, int dataLen);
|
|
188
|
+
|
|
189
|
+
// PubSubSubscribe subscribes to a topic
|
|
190
|
+
//
|
|
191
|
+
extern __declspec(dllexport) long long int PubSubSubscribe(char* repoPath, char* topic);
|
|
192
|
+
|
|
193
|
+
// PubSubNextMessage gets the next message from a subscription
|
|
194
|
+
//
|
|
195
|
+
extern __declspec(dllexport) char* PubSubNextMessage(long long int subID);
|
|
196
|
+
|
|
197
|
+
// PubSubUnsubscribe unsubscribes from a topic
|
|
198
|
+
//
|
|
199
|
+
extern __declspec(dllexport) int PubSubUnsubscribe(long long int subID);
|
|
200
|
+
|
|
201
|
+
// PubSubPeers lists peers participating in a topic
|
|
202
|
+
//
|
|
203
|
+
extern __declspec(dllexport) char* PubSubPeers(char* repoPath, char* topic);
|
|
204
|
+
|
|
205
|
+
// PubSubCloseRepoSubscriptions closes all active pubsub subscriptions for a specific repository
|
|
206
|
+
//
|
|
207
|
+
extern __declspec(dllexport) int PubSubCloseRepoSubscriptions(char* repoPath);
|
|
208
|
+
|
|
209
|
+
// PubSubCloseAllSubscriptions closes all active pubsub subscriptions across all repositories
|
|
210
|
+
//
|
|
211
|
+
extern __declspec(dllexport) int PubSubCloseAllSubscriptions();
|
|
212
|
+
|
|
213
|
+
// CreateRepo initializes a new IPFS repository
|
|
214
|
+
//
|
|
215
|
+
extern __declspec(dllexport) int CreateRepo(char* repoPath);
|
|
216
|
+
extern __declspec(dllexport) int RunNode(char* repoPath);
|
|
217
|
+
|
|
218
|
+
// PubSubEnable enables pubsub on an IPFS node configuration
|
|
219
|
+
//
|
|
220
|
+
extern __declspec(dllexport) int PubSubEnable(char* repoPath);
|
|
221
|
+
extern __declspec(dllexport) char* TestGetString();
|
|
222
|
+
|
|
223
|
+
// GetNodeID gets the ID of the IPFS node
|
|
224
|
+
//
|
|
225
|
+
extern __declspec(dllexport) char* GetNodeID(char* repoPath);
|
|
226
|
+
|
|
227
|
+
// GetNodeMultiAddrs gets the ID of the IPFS node
|
|
228
|
+
//
|
|
229
|
+
extern __declspec(dllexport) char* GetNodeMultiAddrs(char* repoPath);
|
|
230
|
+
|
|
231
|
+
// CleanupNode explicitly releases a node by path
|
|
232
|
+
//
|
|
233
|
+
extern __declspec(dllexport) int CleanupNode(char* repoPath);
|
|
234
|
+
|
|
235
|
+
#ifdef __cplusplus
|
|
236
|
+
}
|
|
237
|
+
#endif
|