Commit a8d4677e authored by Kaiden Fey's avatar Kaiden Fey Committed by Katharina Fey

Fixing netmod-tcp API usage

parent 8e59dd98
......@@ -1593,7 +1593,7 @@ dependencies = [
[[package]]
name = "netmod-tcp"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"async-std",
"async-trait",
......
......@@ -17,14 +17,17 @@ pub(crate) struct State {
impl State {
/// Create a new run state
pub(crate) async fn new(cfg: &Config) -> State {
let ep = Endpoint::new(&cfg.addr, cfg.port, "qaul-hubd")
.await
.unwrap();
ep.mode(match cfg.mode.as_str() {
"dynamic" => Mode::Dynamic,
_ => Mode::Static,
})
.await;
let ep = Endpoint::new(
&cfg.addr,
cfg.port,
"qaul-hubd",
match cfg.mode.as_str() {
"dynamic" => Mode::Dynamic,
_ => Mode::Static,
},
)
.await
.unwrap();
let mut buf = String::new();
let mut peersfd = File::open(&cfg.peers).unwrap();
......@@ -43,7 +46,7 @@ impl State {
set
});
ep.load_peers(peers.into_iter().collect()).await.unwrap();
ep.add_peers(peers.into_iter().collect()).await.unwrap();
let router = Router::new();
router.add_endpoint(ep).await;
......
use async_std::task;
use netmod_tcp::Endpoint;
use netmod_tcp::{Endpoint, Mode};
use ratman::Router;
use std::{
env,
......@@ -13,8 +13,8 @@ async fn main() {
let port = str::parse(&args.remove(1)).unwrap();
let peer_port = str::parse(&args.remove(1)).unwrap();
let mut ep = Endpoint::new("0.0.0.0", port, "").await.unwrap();
ep.load_peers(vec![SocketAddrV4::new(
let mut ep = Endpoint::new("0.0.0.0", port, "", Mode::Static).await.unwrap();
ep.add_peers(vec![SocketAddrV4::new(
Ipv4Addr::new(127, 0, 0, 1),
peer_port,
)])
......
......@@ -8,7 +8,7 @@ edition = "2018"
[dependencies]
async-std = { version = "1.0", features = ["attributes"] }
netmod-mem = { version = "0.1", path = "../../netmods/netmod-mem" }
netmod-tcp = { version = "0.1", path = "../../netmods/netmod-tcp" }
netmod-tcp = { version = "0.2", path = "../../netmods/netmod-tcp" }
netmod-udp = { version = "0.1", path = "../../netmods/netmod-udp" }
ratman = { version = "0.1", path = ".." }
serde = { version = "1.0", features = ["derive"] }
......
......@@ -98,12 +98,19 @@ impl Network {
addr,
port,
peers,
dynamic: _,
dynamic,
} => {
use netmod_tcp::Endpoint;
use netmod_tcp::{Endpoint, Mode};
block_on(async {
let ep = Endpoint::new(&addr, port, "qauld").await.unwrap();
ep.load_peers(peers).await.unwrap();
let ep = Endpoint::new(
&addr,
port,
"qauld",
if dynamic { Mode::Dynamic } else { Mode::Static },
)
.await
.unwrap();
ep.add_peers(peers).await.unwrap();
router.add_endpoint(ep).await;
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment