This rewrite consists of both a migration to an asynchronous model and a migration to the proposed RabbitMQ architecture, because the lapin crate is one of the most mature AMQP client crates for Rust, except it's asynchronous
This task listens on the exclusive queue that will get rule updates. It doesn't really matter what comes over this queue, since it will be discarded. Each client will establish it's own, exclusive queue and bind it to the rule_updates fanout exchange. Mainframe will dispatch a message to all on this queue whenever the rules are updated. Clients will then have to fetch the new rules from /rules, compile the rules, and update their local state.
https://github.com/vipyrsec/dragonfly-client-rs/blob/510e63a320080efea1cc83d19bb23bc7761522ef/src/main.rs#L121-L131
This rewrite consists of both a migration to an asynchronous model and a migration to the proposed RabbitMQ architecture, because the
lapin
crate is one of the most mature AMQP client crates for Rust, except it's asynchronousHere is the gist of the new structure:
This task will continuously refresh the access token, this makes it so that each task doesn't have to send a request, check if it's authentication failed, then re-send it. Now, all operations can simply assume the authentication is update to date. This task will refresh the access tokens 10 seconds early just to have some built-in tolerance. https://github.com/vipyrsec/dragonfly-client-rs/blob/510e63a320080efea1cc83d19bb23bc7761522ef/src/main.rs#L109-L119
This task listens on the exclusive queue that will get rule updates. It doesn't really matter what comes over this queue, since it will be discarded. Each client will establish it's own, exclusive queue and bind it to the
rule_updates
fanout exchange. Mainframe will dispatch a message to all on this queue whenever the rules are updated. Clients will then have to fetch the new rules from/rules
, compile the rules, and update their local state. https://github.com/vipyrsec/dragonfly-client-rs/blob/510e63a320080efea1cc83d19bb23bc7761522ef/src/main.rs#L121-L131This loop listens on the
jobs
queue for incoming jobs, and creates a task for each of them. https://github.com/vipyrsec/dragonfly-client-rs/blob/510e63a320080efea1cc83d19bb23bc7761522ef/src/main.rs#L133-L151