Add HOWTO Python.
This commit is contained in:
@@ -62,6 +62,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
env CC=gcc CFLAGS='-Werror' ./autogen.sh
|
env CC=gcc CFLAGS='-Werror' ./autogen.sh
|
||||||
make
|
make
|
||||||
|
sudo make install
|
||||||
- name: Generate Python bindings
|
- name: Generate Python bindings
|
||||||
run: |
|
run: |
|
||||||
cd python
|
cd python
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Python Bindings Development Guide
|
||||||
|
|
||||||
|
The aim of this document is to guide when extending these bindings with additional nDPI API.
|
||||||
|
In the following we suppose that we want to add the following API to ndpi python package.
|
||||||
|
|
||||||
|
``` c
|
||||||
|
int ndpi_des_init(struct ndpi_des_struct *des, double alpha, double beta, float significance);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Add it to NDPI_APIS Python definition
|
||||||
|
|
||||||
|
|
||||||
|
[**NDPI_APIS**][py_ndpi_api] must be updated with the this new API your want to add.
|
||||||
|
|
||||||
|
|
||||||
|
## That's it!
|
||||||
|
|
||||||
|
Now this API can be called and used on python side
|
||||||
|
|
||||||
|
``` python
|
||||||
|
from ndpi import, lib, ffi
|
||||||
|
|
||||||
|
des = ffi.new("struct ndpi_des_struct *")
|
||||||
|
alpha = 0.9
|
||||||
|
beta = 0.5
|
||||||
|
lib.ndpi_des_init(des, alpha, beta, 0.05)
|
||||||
|
```
|
||||||
|
|
||||||
|
[py_ndpi_api]: https://github.com/ntop/nDPI/blob/c47d710d8e5281fff2f1f90ff5462c16ac91d50c/python/ndpi/ndpi_build.py#L49
|
||||||
@@ -15,6 +15,7 @@ cd nDPI
|
|||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure
|
./configure
|
||||||
make
|
make
|
||||||
|
sudo make install
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install ndpi package
|
### Install ndpi package
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ If not, see <http://www.gnu.org/licenses/>.
|
|||||||
------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .ndpi import NDPI, NDPIFlow
|
from .ndpi import *
|
||||||
|
|
||||||
|
|
||||||
__author__ = """Zied Aouini"""
|
__author__ = """Zied Aouini"""
|
||||||
|
|||||||
+8
-8
@@ -47,7 +47,7 @@ class NDPI(object):
|
|||||||
|
|
||||||
def process_packet(self, flow, packet, packet_time_ms):
|
def process_packet(self, flow, packet, packet_time_ms):
|
||||||
p = lib.ndpi_detection_process_packet(self._detection_module,
|
p = lib.ndpi_detection_process_packet(self._detection_module,
|
||||||
flow._C,
|
flow.C,
|
||||||
packet,
|
packet,
|
||||||
len(packet),
|
len(packet),
|
||||||
int(packet_time_ms))
|
int(packet_time_ms))
|
||||||
@@ -58,7 +58,7 @@ class NDPI(object):
|
|||||||
|
|
||||||
def giveup(self, flow, enable_guess=True):
|
def giveup(self, flow, enable_guess=True):
|
||||||
p = lib.ndpi_detection_giveup(self._detection_module,
|
p = lib.ndpi_detection_giveup(self._detection_module,
|
||||||
flow._C,
|
flow.C,
|
||||||
enable_guess,
|
enable_guess,
|
||||||
ffi.new("uint8_t*", 0))
|
ffi.new("uint8_t*", 0))
|
||||||
return ndpi_protocol(C=p,
|
return ndpi_protocol(C=p,
|
||||||
@@ -82,20 +82,20 @@ class NDPI(object):
|
|||||||
|
|
||||||
|
|
||||||
class NDPIFlow(object):
|
class NDPIFlow(object):
|
||||||
__slots__ = ("_C")
|
__slots__ = "C"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def confidence(self):
|
def confidence(self):
|
||||||
confidence = self._C.confidence
|
confidence = self.C.confidence
|
||||||
return ndpi_confidence(id=confidence,
|
return ndpi_confidence(id=confidence,
|
||||||
name=ffi.string(lib.ndpi_confidence_get_name(confidence)).decode('utf-8',
|
name=ffi.string(lib.ndpi_confidence_get_name(confidence)).decode('utf-8',
|
||||||
errors='ignore'))
|
errors='ignore'))
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._C = lib.ndpi_py_initialize_flow()
|
self.C = lib.ndpi_py_initialize_flow()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self._C != ffi.NULL:
|
if self.C != ffi.NULL:
|
||||||
lib.ndpi_flow_free(self._C)
|
lib.ndpi_flow_free(self.C)
|
||||||
self._C = ffi.NULL
|
self.C = ffi.NULL
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user