aboutsummaryrefslogtreecommitdiff
path: root/src/client/bridge/gateway
Commit message (Collapse)AuthorAgeFilesLines
* A bunch of typo fixes (#404)Perry Fraser2018-10-011-1/+1
|
* Fix all the dead links in the docsErk-2018-08-094-13/+13
|
* Fix compilation + tests on certain feature combosZeyla Hellyer2018-08-071-0/+10
| | | | | | | | On certain feature combinations, compilation and tests would not function correctly. This commit goes through a number of feature combinations and gates some tests behind the required features and fixes other compilation errors.
* Add From impls for Game, generify Game paramsZeyla Hellyer2018-08-011-2/+14
| | | | | Add more `impl From<T> for Game` implementations, and make `Into<Game>` trait bounds for all function parameters accepting a Game.
* Fix some clippy lintsZeyla Hellyer2018-07-152-4/+4
| | | | | Some lints were not resolved due to causing API changes. Most lints in the framework were left unfixed.
* Fix doc links with no anchorZeyla Hellyer2018-07-111-0/+1
|
* Remove extraneous spaces at the end of linesZeyla Hellyer2018-06-172-4/+4
|
* Remove empty whitespace at ends of linesZeyla Hellyer2018-04-251-3/+3
|
* Refactor imports/exports to use nested groups and better formattingacdenisSK2018-03-296-21/+51
|
* Fix heartbeat checkingZeyla Hellyer2018-03-271-7/+2
| | | | | If a heartbeat acknowledgement is not received, then the shard should restart.
* Fix broken docs links caused by model mod changesZeyla Hellyer2018-01-312-7/+7
| | | | | Fix broken links caused by the `model` module changes in v0.5.0, which split up the module into sub-modules for better organization.
* Expose a client voice managerZeyla Hellyer2018-01-184-73/+107
|
* Use an InterMessage to communicate over gatewayZeyla Hellyer2018-01-185-17/+24
| | | | | | | Instead of communicating over the gateway in a split form of a `serde_json::Value` or a `client::bridge::gateway::ShardClientMessage`, wrap them both into a single enum for better interaction between the client, gateway, and voice modules.
* Fix ShardManager doctestZeyla Hellyer2018-01-101-11/+14
|
* Simplify ShardManager creationZeyla Hellyer2018-01-102-72/+26
| | | | | | Instead of creating different `new` functions for every bridged feature combination, accept a struct of options. Structs can have conditional fields, unlike functions which can not have conditional arguments.
* Add an event for shard updatesZeyla Hellyer2018-01-013-3/+43
| | | | | Add an event in the EventHandler to be called when a shard updates its Connection Stage.
* Expose a method of retrieving shard status/latencyZeyla Hellyer2018-01-014-1/+52
| | | | | | This exposes a method of retrieving a shard's status and latency through the Shard Manager, as part of the existing Shard Runner Info struct. The Shard Runner will update this whenever it notices a change.
* Add missing trailing comma in matchZeyla Hellyer2017-12-171-1/+1
|
* Fix doc-tests and `single_zc`acdenisSK2017-12-171-5/+5
|
* Fix shards attempting to re-identify on their ownZeyla Hellyer2017-12-161-8/+24
| | | | | | | | | | Fix shards by taking away their responsibility to re-identify, instead shutting down shard runners and going through the shard queuer to restart a shard runner and its associated shard. This fixes the case where a running shard's session invalidates and re-IDENTIFYs within 5 seconds before queued shard starts, causing a cascading failure of sessions for new shards.
* Fix most clippy lints, take more refeerncesZeyla Hellyer2017-12-162-13/+13
| | | | | Fix clippy lints and subsequently accept references for more function parameters.
* Attempt to restart failed shard bootsZeyla Hellyer2017-12-162-18/+48
| | | | | | | | | | | | When the ShardQueuer fails to restart a shard (such as due to a network error, an issue on Discord's side, Cloudflare, etc.), it will now push the ID onto a queue. Every 5 seconds messages will attempt to be read from the receiver, and if one is not read after the timeout, a queued shard start will occur (if one is queued). This should fix a number of reconnection issues.
* Break up the model moduleZeyla Hellyer2017-12-162-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `model` module has historically been one giant module re-exporting all of the model types, which is somewhere around 100 types. This can be a lot to look at for a new user and somewhat overwhelming, especially with a large number of fine-grained imports from the module. The module is now neatly split up into submodules, mostly like it has been internally since the early versions of the library. The submodules are: - application - channel - error - event - gateway - guild - id - invite - misc - permissions - prelude - user - voice - webhook Each submodule contains types that are "owned" by the module. For example, the `guild` submodule contains, but not limited to, Emoji, AuditLogsEntry, Role, and Member. `channel` contains, but not limited to, Attachment, Embed, Message, and Reaction. Upgrade path: Instead of glob importing the models via `use serenity::model::*;`, instead glob import via the prelude: ```rust use serenity::model::prelude::*; ``` Instead of importing from the root model module: ```rust use serenity::model::{Guild, Message, OnlineStatus, Role, User}; ``` instead import from the submodules like so: ```rust use serenity::model::channel::Message; use serenity::model::guild::{Guild, Role}; use serenity::model::user::{OnlineStatus, User}; ```
* Shutdown everything on ShardManager::shutdown_allZeyla Hellyer2017-12-094-0/+16
| | | | | | | | | | Calling `ShardManager::shutdown_all` will now send a message to the shard queuer and shard monitor to shutdown. This will now cause `Client::start_connection` to exit. Additionally, `Client::start_connection` and related functions that call this (e.g. `Client::start_autosharded`) now return `Ok(())` on clean exits.
* Implement Deserialize for {,Gateway,Voice}EventZeyla Hellyer2017-11-191-2/+7
| | | | | | | | | | | Implement Deserialize for `model::event::GatewayEvent` and `model::event::VoiceEvent`, and derive it for `model::event::Event`. Due to the natural potential slowness of deserializing into`Event` (attempting to deserialize into each variant until successful), a function named `model::event::deserialize_event_with_type` is provided for quickly deserializing into a known type if the dispatch type is known.
* Use the threadpool for framework command executionZeyla Hellyer2017-11-131-29/+11
| | | | | | | Instead of executing framework commands in the shard runner thread (potentially blocking the shard runner from reading new messages over the websocket and heartbeating), dispatch framework commands to the shard runner's threadpool.
* Make ShardManager::runners publicZeyla Hellyer2017-11-091-1/+5
| | | | | | `ShardManager::public` has been made public to allow direct user interaction, but should be used with caution due to the fact this can internally cause an invalid state when used improperly.
* Whoops. Add a `FromStr` impl for `ReactionType`acdenisSK2017-11-041-7/+0
|
* Merge v0.4.3acdenisSK2017-11-041-0/+7
|\
| * Fix shard shutdown via ContextZeyla Hellyer2017-10-292-7/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes the shard shutdown via the Context. This works by setting a "shutdown" field on the Shard struct as being true, indicating that the Shard has shutdown. The Shard Runner detects this and requests a shutdown from the Shard Manager. The ideal solution here would be to add a "Shutdown" variant to serenity::gateway::ConnectionStage, but that would be a breaking change, so we instead need to opt for adding a new struct to gateway::Shard. The Shard Manager has also been updated to only attempt the shutdown of a shard if it doesn't already know for certain that it shut itself down, which avoids an error logged saying that there was an error sending a shutdown message to its Shard Runner. When all shards have been shutdown (for most bots, this will only be one), the Shard Manager will end and the Client will stop its operations, returning thread control to the user.
* | Redo client internals + gatewayZeyla Hellyer2017-11-037-156/+1055
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit is a rewrite of the client module's internals and the gateway. The main benefit of this is that there is either 0 or 1 lock retrievals per event received, and the ability to utilize the ShardManager both internally and in userland code has been improved. The primary rework is in the `serenity::client` module, which now includes a few more structures, some changes to existing ones, and more functionality (such as to the `ShardManager`). The two notable additions to the client-gateway bridge are the `ShardMessenger` and `ShardManagerMonitor`. The `ShardMessenger` is a simple-to-use interface for users to use to interact with shards. The user is given one of these in the `serenity::client::Context` in dispatches to the `serenity::client::EventHandler`. This can be used for updating the presence of a shard, sending a guild chunk message, or sending a user's defined WebSocket message. The `ShardManagerMonitor` is a loop run in its own thread, potentially the main thread, that is responsible for receiving messages over an mpsc channel on what to do with shards via the `ShardManager`. For example, it will receive a message to shutdown a single shard, restart a single shard, or shutdown the entire thing. Users, in most applications, will not interact with the `ShardManagerMonitor`. Users using the `serenity::client::Client` interact with only the `ShardMessenger`. The `ShardManager` is now usable by the user and is available to them, and contains public functions for shutdowns, initializations, restarts, and complete shutdowns of shards. It contains utility functions like determining whether the `ShardManager` is responsible for a shard of a given ID and the IDs of shards currently active (having an associated `ShardRunner`). It can be found on `serenity::client::Client::shard_manager`. Speaking of the `ShardRunner`, it no longer owns a clone of an Arc to its assigned `serenity::gateway::Shard`. It now completely owns the Shard. This means that in order to open the shard, a `ShardRunner` no longer has to repeatedly retrieve a lock to it. This reduces the number of lock retrievals per event dispatching cycle from 3 or 4 depending on event type to 0 or 1 depending on whether it's a message create _and_ if the framework is in use. To interact with the Shard, one must now go through the previously mentioned `ShardMessenger`, which the `ShardRunner` will check for messages from on a loop. `serenity::client::Context` is now slightly different. Instead of the `shard` field being `Arc<Mutex<Shard>>`, it is an instance of a `ShardMessenger`. The interface is the same (minus losing some Shard-specific methods like `latency`), and `Context`'s shortcuts still exist (like `Context::online` or `Context::set_game`). It now additionally includes a `Context::shard_id` field which is a u64 containing the ID of the shard that the event was dispatched from. `serenity::client::Client` has one changed field name, one field that is now public, and a new field. `Client::shard_runners` is now `Client::shard_manager` of type `Arc<Mutex<ShardManager>>`. The `Client::token` field is now public. This can, for example, be mutated on token resets if you know what you're doing. `Client::ws_uri` is new and contains the URI for shards to use when connecting to the gateway. Otherwise, the Client's usage is unchanged. `serenity::gateway::Shard` has a couple of minor changes and many more public methods and fields. The `autoreconnect`, `check_heartbeat`, `handle_event`, `heartbeat`, `identify`, `initialize`, `reset`, `resume`, `reconnect`, and `update_presence` methods are now public. The `token` structfield is now public. There are new getters for various structfields, such as `heartbeat_instants` and `last_heartbeat_ack`. The breaking change on the `Shard` is that `Shard::handle_event` now takes an event by reference and, instead of returning `Result<Option<Event>>`, it now returns `Result<Option<ShardAction>>`. `serenity::gateway::ShardAction` is a light enum determining an action that someone _should_/_must_ perform on the shard, e.g. reconnecting or identifying. This is determined by `Shard::handle_event`. In total, there aren't too many breaking changes that most of userland use cases has to deal with -- at most, changing some usage of `Context`. Retrieving information like a Shard's latency is currently not possible anymore but work will be done to make this functionality available again.
* | Update to account for changes made in 0.4.1acdenisSK2017-10-143-15/+20
|\|
| * Fix clippy lintsZeyla Hellyer2017-10-113-15/+20
| |
| * Make the client threadpool user-customizableZeyla Hellyer2017-10-093-15/+26
| | | | | | | | | | | | In addition to making the threadpool used by client shards customizable by the user, make only a single threadpool (as opposed to one per shard) and share it across all shards.
| * Add a threadpool to the shard runnerZeyla Hellyer2017-10-091-10/+36
| | | | | | | | | | | | A threadpool will help with giving event dispatches a threaded behaviour while still allowing the library the ability to perform other actions, such as receiving new events and heartbeating over the websocket client.
| * Fix most clippy warningsMaiddog2017-10-042-14/+2
| |
| * Rename an internal Shard Runner methodZeyla Hellyer2017-09-301-2/+2
| | | | | | | | | | `ShardRunner::recv_events` actually only receives one event, so de-pluralize it.
| * Improve shard logicZeyla Hellyer2017-09-301-83/+75
| | | | | | | | | | | | | | | | | | | | Improve shard logic by more cleanly differentiating when resuming, as well as actually fixing resume logic. For shard runners, better handling of dead clients is added, as well as more use of the shard manager, in that the runner will now more liberally request a restart when required (instead of sitting and doing nothing infinitely).
| * Improve shard and shard runner loggingZeyla Hellyer2017-09-301-3/+19
| |
* | Switch to parking_lot::{Mutex, RwLock}Zeyla Hellyer2017-10-103-18/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Switch to the `parking_lot` crate's implementations of `std::sync::Mutex` and `std::sync::RwLock`, which are more efficient. A writeup on why `parking_lot` is more efficient can be read here: <https://github.com/Amanieu/parking_lot> Upgrade path: Modify `mutex.lock().unwrap()` usage to `mutex.lock()` (not needing to unwrap or handle a result), and `rwlock.read().unwrap()`/`rwlock.write().unwrap()` usage to `rwlock.read()` and `rwlock.write()`. For example, modify: ```rust use serenity::CACHE; println!("{}", CACHE.read().unwrap().user.id); ``` to: ```rust use serenity::CACHE; println!("{}", CACHE.read().user.id); ```
* | Make the client threadpool user-customizableZeyla Hellyer2017-10-093-15/+26
| | | | | | | | | | | | In addition to making the threadpool used by client shards customizable by the user, make only a single threadpool (as opposed to one per shard) and share it across all shards.
* | Add a threadpool to the shard runnerZeyla Hellyer2017-10-091-10/+36
| | | | | | | | | | | | A threadpool will help with giving event dispatches a threaded behaviour while still allowing the library the ability to perform other actions, such as receiving new events and heartbeating over the websocket client.
* | Fix most clippy warningsMaiddog2017-10-092-14/+2
| |
* | Rename an internal Shard Runner methodZeyla Hellyer2017-10-091-2/+2
| | | | | | | | | | `ShardRunner::recv_events` actually only receives one event, so de-pluralize it.
* | Improve shard logicZeyla Hellyer2017-10-091-83/+75
| | | | | | | | | | | | | | | | | | | | Improve shard logic by more cleanly differentiating when resuming, as well as actually fixing resume logic. For shard runners, better handling of dead clients is added, as well as more use of the shard manager, in that the runner will now more liberally request a restart when required (instead of sitting and doing nothing infinitely).
* | Improve shard and shard runner loggingZeyla Hellyer2017-10-091-3/+19
|/
* Fix client shards by cloning ShardManager runnersZeyla Hellyer2017-09-273-2/+4
| | | | | | Due to the new ShardManager, `Client::shards` would never fill, so instead clone the `shard_runners` instance from the `ShardManager` to the `Client`.
* Fix client no-framework compilationZeyla Hellyer2017-09-273-32/+78
|
* Fix tests and example 05Zeyla Hellyer2017-09-242-4/+1
|
* Add a shard managerZeyla Hellyer2017-09-244-0/+506
The shard manager will queue up shards for booting.