Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Upgrade to v2 connection (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
feymartynov committed Dec 12, 2019
1 parent 8f7f2c6 commit 6a40ed5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 43 deletions.
18 changes: 9 additions & 9 deletions src/app/endpoint/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use chrono::{DateTime, Utc};
use serde_derive::{Deserialize, Serialize};
use std::ops::Bound;
use svc_agent::mqtt::{
Connection, IncomingRequest, OutgoingRequest, ResponseStatus, ShortTermTimingProperties,
IncomingRequest, OutgoingRequest, ResponseStatus, ShortTermTimingProperties,
};
use svc_agent::Addressable;
use svc_agent::{Addressable, AgentId};
use svc_error::Error as SvcError;
use uuid::Uuid;

Expand Down Expand Up @@ -60,14 +60,14 @@ pub(crate) struct EnterRequestData {

#[derive(Debug, Serialize)]
struct SubscriptionRequest {
subject: Connection,
subject: AgentId,
object: Vec<String>,
}

impl SubscriptionRequest {
fn new(subject: Connection, object: Vec<&str>) -> Self {
fn new(subject: AgentId, object: Vec<&str>) -> Self {
Self {
subject: subject,
subject,
object: object.iter().map(|&s| s.into()).collect(),
}
}
Expand Down Expand Up @@ -288,7 +288,7 @@ impl State {
agent::InsertQuery::new(inreq.properties().as_agent_id(), object.id()).execute(&conn)?;

let payload = SubscriptionRequest::new(
inreq.properties().to_connection(),
inreq.properties().as_agent_id().to_owned(),
vec!["rooms", &room_id, "events"],
);

Expand Down Expand Up @@ -339,7 +339,7 @@ impl State {
}

let payload = SubscriptionRequest::new(
inreq.properties().to_connection(),
inreq.properties().as_agent_id().to_owned(),
vec!["rooms", &room_id, "events"],
);

Expand Down Expand Up @@ -875,7 +875,7 @@ mod test {
assert_eq!(method, "subscription.create");

let resp: RoomEnterLeaveBrokerRequest = parse_payload(message_value).unwrap();
assert_eq!(resp.subject, format!("v1/agents/{}", agent.agent_id()));
assert_eq!(resp.subject, agent.agent_id().to_string());
assert_eq!(
resp.object,
vec!["rooms", room.id().to_string().as_str(), "events"]
Expand Down Expand Up @@ -1056,7 +1056,7 @@ mod test {
assert_eq!(method, "subscription.delete");

let resp: RoomEnterLeaveBrokerRequest = parse_payload(message_value).unwrap();
assert_eq!(resp.subject, format!("v1/agents/{}", agent.agent_id()));
assert_eq!(resp.subject, agent.agent_id().to_string());
assert_eq!(
resp.object,
vec!["rooms", room.id().to_string().as_str(), "events"]
Expand Down
10 changes: 3 additions & 7 deletions src/app/endpoint/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ mod test {

use diesel::prelude::*;
use serde_json::{json, Value as JsonValue};
use svc_agent::Destination;
use svc_agent::{AccountId, AgentId, Destination};

use crate::test_helpers::{
agent::TestAgent,
Expand Down Expand Up @@ -636,9 +636,7 @@ mod test {
#[derive(Debug, PartialEq, Deserialize)]
struct RtcConnectTransactionReqp {
method: String,
agent_label: String,
account_label: String,
audience: String,
agent_id: AgentId,
}

#[test]
Expand Down Expand Up @@ -695,9 +693,7 @@ mod test {
session_id: backend.session_id(),
reqp: RtcConnectTransactionReqp {
method: "rtc.connect".to_string(),
agent_label: "web".to_string(),
account_label: "user123".to_string(),
audience: AUDIENCE.to_string(),
agent_id: AgentId::new("web", AccountId::new("user123", AUDIENCE)),
}
}
)
Expand Down
22 changes: 11 additions & 11 deletions src/app/endpoint/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) type CreateDeleteEvent = IncomingEvent<CreateDeleteEventData>;

#[derive(Deserialize)]
pub(crate) struct CreateDeleteEventData {
subject: Connection,
subject: AgentId,
object: Vec<String>,
}

Expand Down Expand Up @@ -59,7 +59,7 @@ impl State {
) -> endpoint::Result {
self.is_broker(&evt.properties())?;

let agent_id = evt.payload().subject.agent_id();
let agent_id = &evt.payload().subject;
let room_id = parse_room_id(&evt)?;

let conn = self.db.get()?;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl State {
) -> endpoint::Result {
self.is_broker(&evt.properties())?;

let agent_id = evt.payload().subject.agent_id();
let agent_id = &evt.payload().subject;
let room_id = parse_room_id(&evt)?;

let conn = self.db.get()?;
Expand Down Expand Up @@ -249,7 +249,7 @@ mod test {
// Send subscription.create event.
let payload = json!({
"object": vec!["rooms", &room.id().to_string(), "events"],
"subject": format!("v1/agents/{}", user_agent.agent_id()),
"subject": user_agent.agent_id().to_string(),
});

let broker_agent = TestAgent::new("alpha", "mqtt-gateway", AUDIENCE);
Expand Down Expand Up @@ -299,7 +299,7 @@ mod test {

let payload = json!({
"object": vec!["rooms", &Uuid::new_v4().to_string(), "events"],
"subject": format!("v1/agents/{}", user_agent.agent_id()),
"subject": user_agent.agent_id().to_string(),
});

let broker_agent = TestAgent::new("web", "wrong_user", AUDIENCE);
Expand Down Expand Up @@ -328,7 +328,7 @@ mod test {

let payload = json!({
"object": vec!["rooms", &Uuid::new_v4().to_string(), "events"],
"subject": format!("v1/agents/{}", user_agent.agent_id()),
"subject": user_agent.agent_id().to_string(),
});

let broker_agent = TestAgent::new("web", "mqtt-gateway", AUDIENCE);
Expand Down Expand Up @@ -357,7 +357,7 @@ mod test {

let payload = json!({
"object": vec!["wrong"],
"subject": format!("v1/agents/{}", user_agent.agent_id()),
"subject": user_agent.agent_id().to_string(),
});

let broker_agent = TestAgent::new("web", "mqtt-gateway", AUDIENCE);
Expand Down Expand Up @@ -394,7 +394,7 @@ mod test {
// Send subscription.delete event.
let payload = json!({
"object": vec!["rooms", &db_agent.room_id().to_string(), "events"],
"subject": format!("v1/agents/{}", db_agent.agent_id()),
"subject": db_agent.agent_id().to_string(),
});

let broker_agent = TestAgent::new("alpha", "mqtt-gateway", AUDIENCE);
Expand Down Expand Up @@ -438,7 +438,7 @@ mod test {

let payload = json!({
"object": vec!["rooms", &Uuid::new_v4().to_string(), "events"],
"subject": format!("v1/agents/{}", user_agent.agent_id()),
"subject": user_agent.agent_id().to_string(),
});

let broker_agent = TestAgent::new("web", "wrong_user", AUDIENCE);
Expand Down Expand Up @@ -467,7 +467,7 @@ mod test {

let payload = json!({
"object": vec!["rooms", &Uuid::new_v4().to_string(), "events"],
"subject": format!("v1/agents/{}", user_agent.agent_id()),
"subject": user_agent.agent_id().to_string(),
});

let broker_agent = TestAgent::new("web", "mqtt-gateway", AUDIENCE);
Expand Down Expand Up @@ -496,7 +496,7 @@ mod test {

let payload = json!({
"object": vec!["wrong"],
"subject": format!("v1/agents/{}", user_agent.agent_id()),
"subject": user_agent.agent_id().to_string(),
});

let broker_agent = TestAgent::new("web", "mqtt-gateway", AUDIENCE);
Expand Down
29 changes: 13 additions & 16 deletions src/test_helpers/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,25 @@ impl TestAgent {
.take(CORRELATION_DATA_LENGTH)
.collect();

let conference_account_id = AccountId::new("svc", self.account_id.audience());
let conference_agent_id = AgentId::new("conference", conference_account_id);
let response_topic = format!("agents/{}/api/v1/in/{}", self.agent_id, conference_agent_id);
let now = Utc::now().timestamp_millis().to_string();
let conference_account_id = AccountId::new("conference", self.account_id.audience());

let response_topic = format!(
"agents/{}/api/v1/in/{}",
self.agent_id, conference_account_id
);

let message = json!({
"payload": serde_json::to_string(payload)?,
"properties": {
"type": "request",
"correlation_data": correlation_data,
"method": method,
"agent_label": self.agent_id.label(),
"account_label": self.account_id.label(),
"audience": self.account_id.audience(),
"connection_mode": "agents",
"connection_version": "v1",
"agent_id": self.agent_id.to_string(),
"connection_mode": "default",
"connection_version": "v2",
"response_topic": response_topic,
"broker_agent_label": "alpha",
"broker_account_label": "mqtt-gateway",
"broker_audience": self.account_id.audience(),
"broker_agent_id": self.account_id.to_string(),
"broker_timestamp": now,
"broker_processing_timestamp": now,
"broker_initial_processing_timestamp": now,
Expand Down Expand Up @@ -94,11 +93,9 @@ impl TestAgent {
"properties": {
"type": "event",
"label": label,
"agent_label": self.agent_id.label(),
"account_label": &self.account_id.label(),
"audience": self.account_id.audience(),
"connection_mode": "agents",
"connection_version": "v1",
"agent_id": self.agent_id.to_string(),
"connection_mode": "default",
"connection_version": "v2",
"broker_timestamp": now,
"broker_processing_timestamp": now,
"broker_initial_processing_timestamp": now,
Expand Down

0 comments on commit 6a40ed5

Please sign in to comment.