mirror of
https://github.com/mii443/miibgpd.git
synced 2025-08-22 15:55:26 +00:00
add OpenSent state
This commit is contained in:
@ -42,22 +42,8 @@ impl Connection {
|
||||
"waiting connection from remote peer, local-ip={:?}, bgp-port={}",
|
||||
config.local_ip, BGP_PORT
|
||||
);
|
||||
let listener = TcpListener::bind((config.local_ip, BGP_PORT))
|
||||
.await
|
||||
.unwrap()
|
||||
/*.context(format!(
|
||||
"cannot bind to local-ip={:?}, bgp-port={}",
|
||||
config.local_ip, BGP_PORT
|
||||
))?*/;
|
||||
let listener = TcpListener::bind((config.local_ip, BGP_PORT)).await?;
|
||||
|
||||
Ok(listener
|
||||
.accept()
|
||||
.await
|
||||
.unwrap()
|
||||
/*.context(format!(
|
||||
"cannot accept connection from remote peer, local-ip={:?}, bgp-port={}",
|
||||
config.local_ip, BGP_PORT
|
||||
))?*/
|
||||
.0)
|
||||
Ok(listener.accept().await?.0)
|
||||
}
|
||||
}
|
||||
|
27
src/peer.rs
27
src/peer.rs
@ -52,6 +52,13 @@ impl Peer {
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
State::Connect => match event {
|
||||
Event::TcpConnectionConfirmed => {
|
||||
info!("state transitioned from Connect to OpenSent");
|
||||
self.state = State::OpenSent;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@ -82,4 +89,24 @@ mod tests {
|
||||
peer.next().await;
|
||||
assert_eq!(peer.state, State::Connect);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn peer_can_transition_to_open_sent_state() {
|
||||
let config: Config = "64512 127.0.0.1 65413 127.0.0.2 active".parse().unwrap();
|
||||
let mut peer = Peer::new(config);
|
||||
peer.start();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let remote_config = "64513 127.0.0.2 65412 127.0.0.1 passive".parse().unwrap();
|
||||
let mut remote_peer = Peer::new(remote_config);
|
||||
remote_peer.start();
|
||||
remote_peer.next().await;
|
||||
remote_peer.next().await;
|
||||
});
|
||||
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
peer.next().await;
|
||||
peer.next().await;
|
||||
assert_eq!(peer.state, State::OpenSent);
|
||||
}
|
||||
}
|
||||
|
@ -2,4 +2,5 @@
|
||||
pub enum State {
|
||||
Idle,
|
||||
Connect,
|
||||
OpenSent,
|
||||
}
|
||||
|
Reference in New Issue
Block a user