|
|
|
|
@ -142,11 +142,10 @@ impl BitTorrentDHTState {
|
|
|
|
|
|
|
|
|
|
// C exports.
|
|
|
|
|
|
|
|
|
|
export_tx_data_get!(bittorrent_dht_get_tx_data, BitTorrentDHTTransaction);
|
|
|
|
|
export_state_data_get!(bittorrent_dht_get_state_data, BitTorrentDHTState);
|
|
|
|
|
export_tx_data_get!(get_tx_data, BitTorrentDHTTransaction);
|
|
|
|
|
export_state_data_get!(get_state_data, BitTorrentDHTState);
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub extern "C" fn rs_bittorrent_dht_state_new(
|
|
|
|
|
extern "C" fn state_new(
|
|
|
|
|
_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto,
|
|
|
|
|
) -> *mut std::os::raw::c_void {
|
|
|
|
|
let state = BitTorrentDHTState::new();
|
|
|
|
|
@ -154,41 +153,36 @@ pub extern "C" fn rs_bittorrent_dht_state_new(
|
|
|
|
|
return Box::into_raw(boxed) as *mut std::os::raw::c_void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub unsafe extern "C" fn rs_bittorrent_dht_state_free(state: *mut std::os::raw::c_void) {
|
|
|
|
|
unsafe extern "C" fn state_free(state: *mut std::os::raw::c_void) {
|
|
|
|
|
std::mem::drop(Box::from_raw(state as *mut BitTorrentDHTState));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub unsafe extern "C" fn rs_bittorrent_dht_state_tx_free(
|
|
|
|
|
unsafe extern "C" fn state_tx_free(
|
|
|
|
|
state: *mut std::os::raw::c_void, tx_id: u64,
|
|
|
|
|
) {
|
|
|
|
|
let state = cast_pointer!(state, BitTorrentDHTState);
|
|
|
|
|
state.free_tx(tx_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub unsafe extern "C" fn rs_bittorrent_dht_parse_ts(
|
|
|
|
|
unsafe extern "C" fn parse_ts(
|
|
|
|
|
_flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void,
|
|
|
|
|
stream_slice: StreamSlice, _data: *const std::os::raw::c_void,
|
|
|
|
|
) -> AppLayerResult {
|
|
|
|
|
return rs_bittorrent_dht_parse(
|
|
|
|
|
return parse(
|
|
|
|
|
_flow, state, _pstate, stream_slice,
|
|
|
|
|
_data, Direction::ToServer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub unsafe extern "C" fn rs_bittorrent_dht_parse_tc(
|
|
|
|
|
unsafe extern "C" fn parse_tc(
|
|
|
|
|
_flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void,
|
|
|
|
|
stream_slice: StreamSlice, _data: *const std::os::raw::c_void,
|
|
|
|
|
) -> AppLayerResult {
|
|
|
|
|
return rs_bittorrent_dht_parse(
|
|
|
|
|
return parse(
|
|
|
|
|
_flow, state, _pstate, stream_slice,
|
|
|
|
|
_data, Direction::ToClient);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub unsafe extern "C" fn rs_bittorrent_dht_parse(
|
|
|
|
|
unsafe extern "C" fn parse(
|
|
|
|
|
_flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void,
|
|
|
|
|
stream_slice: StreamSlice, _data: *const std::os::raw::c_void,
|
|
|
|
|
direction: Direction,
|
|
|
|
|
@ -198,8 +192,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_parse(
|
|
|
|
|
state.parse(buf, direction).into()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx(
|
|
|
|
|
unsafe extern "C" fn state_get_tx(
|
|
|
|
|
state: *mut std::os::raw::c_void, tx_id: u64,
|
|
|
|
|
) -> *mut std::os::raw::c_void {
|
|
|
|
|
let state = cast_pointer!(state, BitTorrentDHTState);
|
|
|
|
|
@ -213,16 +206,14 @@ pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx_count(
|
|
|
|
|
unsafe extern "C" fn state_get_tx_count(
|
|
|
|
|
state: *mut std::os::raw::c_void,
|
|
|
|
|
) -> u64 {
|
|
|
|
|
let state = cast_pointer!(state, BitTorrentDHTState);
|
|
|
|
|
return state.tx_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub unsafe extern "C" fn rs_bittorrent_dht_tx_get_alstate_progress(
|
|
|
|
|
unsafe extern "C" fn tx_get_alstate_progress(
|
|
|
|
|
tx: *mut std::os::raw::c_void, _direction: u8,
|
|
|
|
|
) -> std::os::raw::c_int {
|
|
|
|
|
let tx = cast_pointer!(tx, BitTorrentDHTTransaction);
|
|
|
|
|
@ -235,8 +226,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_tx_get_alstate_progress(
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx_iterator(
|
|
|
|
|
unsafe extern "C" fn state_get_tx_iterator(
|
|
|
|
|
_ipproto: u8, _alproto: AppProto, state: *mut std::os::raw::c_void, min_tx_id: u64,
|
|
|
|
|
_max_tx_id: u64, istate: &mut u64,
|
|
|
|
|
) -> applayer::AppLayerGetTxIterTuple {
|
|
|
|
|
@ -257,7 +247,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_state_get_tx_iterator(
|
|
|
|
|
const PARSER_NAME: &[u8] = b"bittorrent-dht\0";
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() {
|
|
|
|
|
pub unsafe extern "C" fn SCRegisterBittorrentDhtUdpParser() {
|
|
|
|
|
let parser = RustParser {
|
|
|
|
|
name: PARSER_NAME.as_ptr() as *const std::os::raw::c_char,
|
|
|
|
|
default_port: std::ptr::null(),
|
|
|
|
|
@ -266,24 +256,24 @@ pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() {
|
|
|
|
|
probe_tc: None,
|
|
|
|
|
min_depth: 0,
|
|
|
|
|
max_depth: 16,
|
|
|
|
|
state_new: rs_bittorrent_dht_state_new,
|
|
|
|
|
state_free: rs_bittorrent_dht_state_free,
|
|
|
|
|
tx_free: rs_bittorrent_dht_state_tx_free,
|
|
|
|
|
parse_ts: rs_bittorrent_dht_parse_ts,
|
|
|
|
|
parse_tc: rs_bittorrent_dht_parse_tc,
|
|
|
|
|
get_tx_count: rs_bittorrent_dht_state_get_tx_count,
|
|
|
|
|
get_tx: rs_bittorrent_dht_state_get_tx,
|
|
|
|
|
state_new,
|
|
|
|
|
state_free,
|
|
|
|
|
tx_free: state_tx_free,
|
|
|
|
|
parse_ts,
|
|
|
|
|
parse_tc,
|
|
|
|
|
get_tx_count: state_get_tx_count,
|
|
|
|
|
get_tx: state_get_tx,
|
|
|
|
|
tx_comp_st_ts: 1,
|
|
|
|
|
tx_comp_st_tc: 1,
|
|
|
|
|
tx_get_progress: rs_bittorrent_dht_tx_get_alstate_progress,
|
|
|
|
|
tx_get_progress: tx_get_alstate_progress,
|
|
|
|
|
get_eventinfo: Some(BitTorrentDHTEvent::get_event_info),
|
|
|
|
|
get_eventinfo_byid: Some(BitTorrentDHTEvent::get_event_info_by_id),
|
|
|
|
|
localstorage_new: None,
|
|
|
|
|
localstorage_free: None,
|
|
|
|
|
get_tx_files: None,
|
|
|
|
|
get_tx_iterator: Some(rs_bittorrent_dht_state_get_tx_iterator),
|
|
|
|
|
get_tx_data: bittorrent_dht_get_tx_data,
|
|
|
|
|
get_state_data: bittorrent_dht_get_state_data,
|
|
|
|
|
get_tx_iterator: Some(state_get_tx_iterator),
|
|
|
|
|
get_tx_data,
|
|
|
|
|
get_state_data,
|
|
|
|
|
apply_tx_config: None,
|
|
|
|
|
flags: 0,
|
|
|
|
|
get_frame_id_by_name: None,
|
|
|
|
|
|