How to create static forwarder #5016
Replies: 3 comments 4 replies
-
Hi @Ranger11Danger this appears to be an issue with the heartbeat implementation that gets triggered when you use a static forwarder. I don't know exactly yet how to fix it but I think that this should not prevent the static forwarder from working properly despite the error messages. Those messages are meaning to say that a new forwarder can not be created because there is already a forwarder at that address. If you want to get rid of those messages you can use a lower-level API and write in the client: let forwarder = RemoteForwarder::create_static_without_heartbeats(
node.context(),
node_in_hub.clone(),
"custom_address",
RemoteForwarderOptions::new(),
).await?; While starting the server as (note the ForwardingService::create(&ctx, "forwarding_service", options).await?; We are going to better diagnose this issue and come back to you. Thanks for reporting it! |
Beta Was this translation helpful? Give feedback.
-
Hey @etorreborre Ive been building off of the example above and setup a basic scenario where a client registers a forward address with the server, and then the client sends a message to the servers "echoer" The server then echos back like normal and the message is received, however in the servers "echoer" worker after it sends a response it also tries to send a message using the forward address the client created to send message to an "echoer" worker running on the client. Essentially creating a ping -> pong -> ping -> pong situation. however when the client receives the message through the forward address and hitting the "echoer" address i recieve and error saying it did not pass outgoing access control. Is there a way to allow that message to come back through? struct Echoer;
#[ockam::worker]
impl Worker for Echoer {
type Context = Context;
type Message = String;
async fn handle_message(&mut self, ctx: &mut Context, msg: Routed<String>) -> Result<()> {
println!("\n[✓] Address: {}, Received: {:?}, Route: {:?}", ctx.address(), msg, msg.return_route());
ctx.send(msg.return_route(), msg.body()).await;
ctx.send(route!["custom_address", "echoer"], "test".to_string()).await
}
}
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
let tcp_listener_options = TcpListenerOptions::new();
let options = ForwardingServiceOptions::new()
.service_as_consumer(
&tcp_listener_options.spawner_flow_control_id(),
FlowControlPolicy::SpawnerAllowMultipleMessages,
)
.forwarder_as_consumer(
&tcp_listener_options.spawner_flow_control_id(),
FlowControlPolicy::SpawnerAllowMultipleMessages,
);
ForwardingService::create(&ctx, "forwarding_service", options).await?;
let node = node(ctx);
node.start_worker("echoer", Echoer, AllowAll, AllowAll).await?;
let tcp = node.create_tcp_transport().await?;
// start the worker that is going to echo back messages
// start the listener for the implant
let listener = tcp
.listen("127.0.0.1:4444", tcp_listener_options)
.await?;
let bob = node.create_identity().await?;
let secure_channel_listener = node
.create_secure_channel_listener(
&bob,
"bob_listener",
SecureChannelListenerOptions::new().as_consumer(
listener.flow_control_id(),
FlowControlPolicy::SpawnerAllowMultipleMessages
),
)
.await?;
node.flow_controls().add_consumer(
"echoer",
secure_channel_listener.flow_control_id(),
FlowControlPolicy::SpawnerAllowMultipleMessages,
);
Ok(())
} Client: struct Echoer;
#[ockam::worker]
impl Worker for Echoer {
type Context = Context;
type Message = String;
async fn handle_message(&mut self, ctx: &mut Context, msg: Routed<String>) -> Result<()> {
println!("\n[✓] Address: {}, Received: {:?}, Route: {:?}", ctx.address(), msg, msg.return_route());
ctx.send(msg.return_route(), msg.body()).await
}
}
#[ockam::node]
async fn main(ctx: Context) -> Result<()> {
let mut node = node(ctx);
node.start_worker("echoer", Echoer, AllowAll, AllowAll).await?;
//Setup Connection to Server
let tcp = node.create_tcp_transport().await?;
let node_in_hub = tcp
.connect("127.0.0.1:4444", TcpConnectionOptions::new())
.await?;
let forwarder = RemoteForwarder::create_static_without_heartbeats(
node.context(),
node_in_hub.clone(),
"custom_address",
RemoteForwarderOptions::new())
.await?;
println!("{:?}", forwarder.remote_address());
//Setup Secure Channel
let alice = node.create_identity().await?;
let r = route![node_in_hub, "bob_listener"];
let channel = node
.create_secure_channel(&alice, r, SecureChannelOptions::new())
.await?;
//Add echoer as consumer
node.flow_controls().add_consumer(
"echoer",
channel.flow_control_id(),
FlowControlPolicy::ProducerAllowMultiple,
);
let reply = node
.send_and_receive::<String>(route![channel, "echoer"], "Hello Ockam!".to_string())
.await?;
println!("App Received: {}", reply); // should print "Hello Ockam!"
Ok(())
} Client Error: WARN ockam_node::context::send_message: Message forwarded from 0#a95e27256baf33609dbdf02ef3afda24 to 0#echoer did not pass outgoing access control |
Beta Was this translation helpful? Give feedback.
-
Hi @etorreborre Thanks for the help, i was able to get it working through the secure channel as well! is there any documentation of the difference between spawners, producers, and consumers. or How the flow control policies work? |
Beta Was this translation helpful? Give feedback.
-
Ive been trying to figure out how to create a simple forwarder and client that creates a forward address
Forwarder:
Client:
Ive gotten this to work using the normal 'create_forwarder' method but when I try and create a static one the logs from the forwarder say this:
I was just wondering if anyone else as any experience with this and could point me i the right direction thanks!
Beta Was this translation helpful? Give feedback.
All reactions