Skip to content

Commit

Permalink
fix example controller
Browse files Browse the repository at this point in the history
Signed-off-by: iGxnon <[email protected]>
  • Loading branch information
iGxnon committed Oct 2, 2024
1 parent 8378353 commit 71fe553
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jobs:
wget https://github.com/mozilla/sccache/releases/download/v0.7.5/sccache-v0.7.5-x86_64-unknown-linux-musl.tar.gz
mkdir sccache-install && tar -xzf sccache-v0.7.5-x86_64-unknown-linux-musl.tar.gz -C sccache-install --strip-components=1
mv sccache-install/sccache /usr/local/bin && rm -rf sccache-install/
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
echo "SCCACHE_GHA_ENABLED=on" >> $GITHUB_ENV
- name: Configure sccache
uses: actions/github-script@v6
with:
script: |
core.exportVariable('RUSTC_WRAPPER', 'sccache')
core.exportVariable('SCCACHE_GHA_ENABLED', 'on')
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
Expand Down
2 changes: 2 additions & 0 deletions examples/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ impl FlushController {

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();

let socket = UdpSocket::bind("127.0.0.1:0").await?;
let local_addr = socket.local_addr()?;
println!("[server] server listening on {local_addr} with flush controller");
Expand Down
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ fix:
cargo machete --fix

check:
cargo audit
cargo fmt --all -- --check
cargo sort --check
cargo machete

test:
cargo nextest run --all-features --features fastrace/enable
40 changes: 22 additions & 18 deletions src/client/handler/online.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,31 @@ where
let Some(body) = ready!(this.frame.as_mut().poll_next(cx)) else {
return Poll::Ready(None);
};
if let FrameBody::ConnectionRequestAccepted {
system_addresses,
accepted_timestamp,
..
} = body
{
this.link.send_frame_body(FrameBody::NewIncomingConnection {
server_address: *this.addr,
match body {
FrameBody::ConnectionRequestAccepted {
system_addresses,
request_timestamp: timestamp(),
accepted_timestamp,
});
*this.state = State::Connected;
debug!(
"[{}] connected to server {addr:?}",
this.role,
addr = this.addr
);
continue;
..
} => {
this.link.send_frame_body(FrameBody::NewIncomingConnection {
server_address: *this.addr,
system_addresses,
request_timestamp: timestamp(),
accepted_timestamp,
});
*this.state = State::Connected;
debug!(
"[{}] connected to server {addr:?}",
this.role,
addr = this.addr
);
continue;
}
FrameBody::User(data) => return Poll::Ready(Some(data)), /* FIXME: we should ignore this packet */
_ => {
debug!("[{}] ignore packet {body:?} on WaitConnRes", this.role);
}
}
debug!("[{}] ignore packet {body:?} on WaitConnRes", this.role);
}
State::Connected => {
let Some(body) = ready!(this.frame.as_mut().poll_next(cx)) else {
Expand Down
2 changes: 1 addition & 1 deletion src/codec/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::packet::{unconnected, Packet};
/// `Framed` is a base structure for socket communication.
/// In this project, it wraps an asynchronous UDP socket and implements the
/// [`Stream`](futures::stream::Stream) and [`Sink`](futures::sink::Sink) traits.
/// This allows for reading and writing RakNet frames over the socket.
/// This allows for reading and writing `RakNet` frames over the socket.
/// It supports both receiving and sending unconnected and connected packets.
pub(crate) struct Framed<T> {
/// The underlying socket that is being wrapped.
Expand Down
6 changes: 3 additions & 3 deletions src/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl ResendMap {
let now = Instant::now();
if now < self.last_record_expired_at {
trace!(
"[{}] skip scanning the resend map, last record expired at {:?}",
"[{}] skip scanning the resend map, last record expired within {:?}",
self.role,
self.last_record_expired_at - now
);
Expand Down Expand Up @@ -397,7 +397,7 @@ impl ResendMap {
self.estimator.clear();
}
trace!(
"[{}]: resend {} stales, {} entries remains",
"[{}] resend {} stales, {} entries remains",
self.role,
len_before - len,
len,
Expand All @@ -423,7 +423,7 @@ impl ResendMap {
}
let c_id = ConnId::new(self.role.guid(), self.peer.guid);
trace!(
"[{}]: wait on {c_id:?} for resend seq_num {} to {} within {:?}",
"[{}] wait on {c_id:?} for resend seq_num {} to {} within {:?}",
self.role,
seq_num,
self.peer,
Expand Down

0 comments on commit 71fe553

Please sign in to comment.