-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcallbacks.py
More file actions
66 lines (50 loc) · 1.85 KB
/
callbacks.py
File metadata and controls
66 lines (50 loc) · 1.85 KB
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
# -*- coding:utf8 -*-
"""
Utility functions and wrapper for callbacks
"""
from __future__ import absolute_import, unicode_literals
import logging
from _rtrlib import ffi
from .manager_group import ManagerGroup, ManagerGroupStatus
from .rtr_socket import RTRSocket
from .records import PFXRecord, SPKIRecord
LOG = logging.getLogger(__name__)
@ffi.def_extern(name="rtr_mgr_status_callback")
def status_callback(rtr_mgr_group, group_status, rtr_socket, object_handle):
"""
Wraps the given python function and wraps it to hide cffi specifics.
This wrapper is only for the status callback of the rtrlib manager.
"""
object_ = ffi.from_handle(object_handle)
object_._status_callback(
ManagerGroup(rtr_mgr_group),
ManagerGroupStatus(group_status),
RTRSocket(rtr_socket),
object_._status_callback_data
)
@ffi.def_extern(name="pfx_table_callback")
def pfx_table_callback(pfx_record, object_handle):
"""
Wraps the pfx_table callback, used for iteration of the pfx table,
to hide cffi specifics
"""
callback, data = ffi.from_handle(object_handle)
callback(PFXRecord(pfx_record), data)
@ffi.def_extern(name="pfx_update_callback")
def pfx_update_callback(pfx_table, record, added):
wrapped_socket = ffi.cast("struct rtr_socket_wrapper *", record.socket)
mgr = ffi.from_handle(wrapped_socket.data)
mgr._pfx_update_callback(
PFXRecord(record),
added,
mgr._pfx_update_callback_data,
)
@ffi.def_extern(name="spki_update_callback")
def spki_update_callback(spki_table, record, added):
wrapped_socket = ffi.cast("struct rtr_socket_wrapper *", record.socket)
mgr = ffi.from_handle(wrapped_socket.data)
mgr._spki_update_callback(
SPKIRecord(record),
added,
mgr._spki_update_callback_data,
)