Skip to content

Commit

Permalink
Merge pull request #344 from NordSecurity/FILE-615_update_moose_track…
Browse files Browse the repository at this point in the history
…er_to_v_13

FILE-615: update moose tracker to v13.1.0
  • Loading branch information
Lipt0nas authored Sep 16, 2024
2 parents bcad37c + 335a12b commit d5f4cba
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 30 deletions.
2 changes: 1 addition & 1 deletion MOOSE_RELEASE_TAG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v7.0.0-libDropApp
v13.1.0-libDropApp
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
### **UNRELEASED**
---
* Add `base_dir` field to the `FilePending` event
* Update moose tracker to v13.1.0
* Adds the `transfer_intent_received` event

---
<br>
Expand Down
14 changes: 14 additions & 0 deletions drop-analytics/src/file_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ enum MooseEventType {
Init(InitEvent),
#[serde(rename = "transfer_intent")]
TransferIntent(crate::TransferIntentEventData),
#[serde(rename = "transfer_intent_received")]
TransferIntentReceived(crate::TransferIntentReceivedEventData),
#[serde(rename = "transfer_state")]
TransferState(crate::TransferStateEventData),
#[serde(rename = "file")]
Expand Down Expand Up @@ -97,6 +99,18 @@ impl super::Moose for FileImpl {
};
}

fn event_transfer_intent_received(&self, data: crate::TransferIntentReceivedEventData) {
let event = self.write_event(MooseEventType::TransferIntentReceived(data));

if event.is_err() {
slog::error!(
self.logger,
"[Moose] Failed to write transfer intent received event: {:?}",
event.err()
);
};
}

fn event_transfer_state(&self, data: crate::TransferStateEventData) {
let event = self.write_event(MooseEventType::TransferState(data));

Expand Down
6 changes: 6 additions & 0 deletions drop-analytics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ pub struct TransferIntentEventData {
pub mime_types: String,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TransferIntentReceivedEventData {
pub transfer_id: String,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TransferStateEventData {
pub protocol_version: i32,
Expand Down Expand Up @@ -88,6 +93,7 @@ pub struct DeveloperExceptionWithValueEventData {
pub trait Moose: Send + Sync {
fn event_init(&self, data: InitEventData);
fn event_transfer_intent(&self, data: TransferIntentEventData);
fn event_transfer_intent_received(&self, data: TransferIntentReceivedEventData);
fn event_transfer_state(&self, data: TransferStateEventData);
fn event_transfer_file(&self, data: TransferFileEventData);

Expand Down
1 change: 1 addition & 0 deletions drop-analytics/src/mock_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub struct MockImpl;
impl super::Moose for MockImpl {
fn event_init(&self, _: crate::InitEventData) {}
fn event_transfer_intent(&self, _: crate::TransferIntentEventData) {}
fn event_transfer_intent_received(&self, _: crate::TransferIntentReceivedEventData) {}
fn event_transfer_state(&self, _: crate::TransferStateEventData) {}
fn event_transfer_file(&self, _: crate::TransferFileEventData) {}
fn developer_exception(&self, _: crate::DeveloperExceptionEventData) {}
Expand Down
27 changes: 21 additions & 6 deletions drop-analytics/src/moose_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ impl super::Moose for MooseImpl {
self.logger,
send_serviceQuality_initialization_init,
data.result,
data.init_duration
data.init_duration,
None
);
}

Expand All @@ -141,7 +142,17 @@ impl super::Moose for MooseImpl {
data.file_sizes,
data.extensions,
data.mime_types,
data.path_ids
data.path_ids,
None
);
}

fn event_transfer_intent_received(&self, data: crate::TransferIntentReceivedEventData) {
moose!(
self.logger,
send_serviceQuality_transfer_intentReceived,
data.transfer_id,
None
);
}

Expand All @@ -151,7 +162,8 @@ impl super::Moose for MooseImpl {
send_serviceQuality_transfer_state,
data.transfer_id,
data.result,
data.protocol_version
data.protocol_version,
None
);
}

Expand All @@ -165,7 +177,8 @@ impl super::Moose for MooseImpl {
data.direction.into(),
data.path_id,
data.phase.into(),
data.transferred
data.transferred,
None
);
}

Expand All @@ -177,7 +190,8 @@ impl super::Moose for MooseImpl {
data.code,
data.name,
data.message,
data.note
data.note,
None
);
}

Expand All @@ -189,7 +203,8 @@ impl super::Moose for MooseImpl {
data.code,
data.name,
data.message,
data.note
data.note,
None
);
}
}
Expand Down
8 changes: 8 additions & 0 deletions drop-transfer/src/ws/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,14 @@ impl TransferEventTx<OutgoingTransfer> {

impl TransferEventTx<IncomingTransfer> {
pub async fn received(&self) {
self.inner
.lock()
.await
.moose
.event_transfer_intent_received(drop_analytics::TransferIntentReceivedEventData {
transfer_id: self.xfer.id().to_string(),
});

self.emit_ongoing(Event::RequestReceived(self.xfer.clone()))
.await;
}
Expand Down
25 changes: 23 additions & 2 deletions test/drop_test/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import socket
import requests
import shutil
import re

from . import event, ffi
from .logger import logger
Expand All @@ -33,7 +34,7 @@ def to_num(s: str):
return s


compare_funcs = [
compare_ops = [
("*", lambda input, value: value is not None),
("<=", lambda input, value: value <= to_num(input)),
(">=", lambda input, value: value >= to_num(input)),
Expand All @@ -48,6 +49,18 @@ def to_num(s: str):
]


def substitute_transfer_id(input: str):
split = input.split(":")
if len(split) != 2:
raise Exception("Malformed transfer_id substitution expression")

return get_uuid(to_num(split[1]))


substitute_pattern = r"(\?\/)(.*)(\/)"
substitute_ops = [("transfer_id", lambda input: substitute_transfer_id(input))]


def compare_json_struct(expected: dict, actual: dict):
for key in expected:
if key is not int:
Expand All @@ -64,7 +77,15 @@ def compare_json_struct(expected: dict, actual: dict):
compare_json_struct(expected_value[i], actual_value[i])
else:
valid = False
for func in compare_funcs:
substitution = re.search(substitute_pattern, str(expected_value))
if substitution is not None:
inner = substitution.group(2)
for sub_entry in substitute_ops:
if inner.startswith(sub_entry[0]):
expected_value = sub_entry[1](inner)
break

for func in compare_ops:
signature = func[0]
op = func[1]
if str(expected_value).startswith(signature):
Expand Down
Loading

0 comments on commit d5f4cba

Please sign in to comment.