A fork of aatxe/irc Rust crate, improved for IRCv3 support.
Find a file
ChanMin Kim bba8648252 Changed ping timeout logic in ping thread
Previously, ping thread might enter infinite reconnect loop.
Consider the following scenario.

1. If at least one ping is sent, last_ping_data is updated.
2. Then there are many activities, so should_ping() becomes false.
3. After some seconds, now().to_timespec() - time > strong.ping_timeout_duration() is satisfied.
4. reconnect()
5. But should_ping() is still false.
6. The condition is still satisfied, so reconnect() again and again.

I made several changes.

Followings are the changes in the code
- Handle PONG message from server.
- Add `waiting_pong_reply' flag in the state. The flag is set if ping is
sent but the corresponding pong did not arrive yet.
- Ping thread checks ping timeout in correct way.
- Sleeping duration for ping is now based on idle time.
- Initialize ping related fields when `reconnect()' is called.

Hopefully, this commit may be related to issue #50.
2016-07-05 06:55:30 +09:00
examples Implemented Display for Message. 2016-03-17 21:39:58 -04:00
src Changed ping timeout logic in ping thread 2016-07-05 06:55:30 +09:00
.gitignore Added some basic data tests. 2014-10-08 18:08:29 -04:00
.travis.yml Updated travis to use stable Rust. 2016-03-25 23:07:47 -04:00
Cargo.toml Bumped version number to 0.11.3. 2016-04-11 23:01:03 -04:00
LICENSE Changed from Unlicense to CC0 for public domain dedication. 2015-02-19 10:59:20 -05:00
mktestconfig.sh Clean up after #14. Updated test config script. 2015-02-17 13:20:59 -05:00
README.md Updated README to offer an example using programmatic configuration, and 2016-06-30 14:10:31 -04:00

irc Build Status Crates.io

A robust, thread-safe IRC library in Rust. The client portion is compliant with RFC 2812, IRCv3.1, IRCv3.2, and includes some additional, common features. It also features automatic reconnection in unstable networking conditions, flexibility allowing easy unit testing, and a number of useful built-in features for building a powerful client quickly. The server portion is still a work in progress. You can find up-to-date, ready-to-use documentation online here. The documentation is generated with the default features. These are, however, strictly optional and can be disabled accordingly.

Getting Started

To start using this library with cargo, you can simply add irc = "0.11.0" to your dependencies to your Cargo.toml file. You'll likely want to take a look at some of the examples, as well as the documentation. You'll also be able to find a small template to get a feel for the library.

Getting Started by Example

extern crate irc;

use std::default::Default;
use irc::client::prelude::*;

fn main() {
    let cfg = Config {
        nickname: Some(format!("irc-rs")),
        server: Some(format!("irc.example.com")),
        channels: Some(vec![format!("#test")])
        .. Default::default()
    };
    let server = IrcServer::from_config(cfg).unwrap();
    server.identify().unwrap();
    for message in server.iter() {
        // Do message processing.
    }
}

It may not seem like much, but all it takes to get started with an IRC connection is the stub above. In just a few lines, you can be connected to a server and procesisng IRC messages as you wish. The library is built with flexibility in mind. If you need to work on multiple threads, simply clone the server and have at it. We'll take care of the rest.

You'll probably find that programmatic configuration is a bit of a chore, and you'll often want to be able to change the configuration between runs of the program (for example, to change the server that you're connecting to). Fortunately, runtime configuration loading is straightforward.

extern crate irc;

use irc::client::prelude::*;

fn main() {
    let server = IrcServer::new("config.json").unwrap();
    server.identify().unwrap();
    for message in server.iter() {
        // Do message processing.
    }
}

Configuration

Like the rest of the IRC crate, configuration is built with flexibility in mind. You can easily create Config objects programmatically and choose your own methods for handling any saving or loading of configuration required. However, for convenience, we've also included the option of loading JSON files with rust-serialize to write configurations. All the fields are optional, and thus any of them can be omitted (though, omitting a nickname or server will cause the program to fail for obvious reasons). That being said, here's an example of a complete configuration:

{
  "owners": [],
  "nickname": "user",
  "nick_password": "password",
  "alt_nicks": ["user_", "user__"],
  "username": "user",
  "realname": "Test User",
  "server": "chat.freenode.net",
  "port": 6697,
  "password": "",
  "use_ssl": true,
  "encoding": "UTF-8",
  "channels": ["#rust", "#haskell"],
  "umodes": "+RB-x",
  "user_info": "I'm a test user for the Rust IRC crate.",
  "ping_time": 180,
  "ping_timeout": 10,
  "options": {
    "key": "value",
    "note": "anything you want can be in here!",
    "and": "you can use it to build your own additional configuration options."
  }
}

Contributing

Contributions to this library would be immensely appreciated. It should be noted that as this is a public domain project, any contributions will thus be released into the public domain as well.