This repository has been archived by the owner on Jun 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: lib/hector.rb lib/hector/concerns/authentication.rb lib/hector/session.rb test/unit/session_test.rb
- Loading branch information
Showing
14 changed files
with
138 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Hector | ||
module Commands | ||
module Pong | ||
def on_pong | ||
@received_pong = true | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Hector | ||
module Concerns | ||
module KeepAlive | ||
def initialize_keep_alive | ||
@received_pong = true | ||
@heartbeat = Hector::Heartbeat.new { on_heartbeat } | ||
end | ||
|
||
def on_heartbeat | ||
if @received_pong | ||
@received_pong = false | ||
respond_with(:ping, Hector.server_name) | ||
else | ||
@quit_message = "Ping timeout" | ||
connection.close_connection(true) | ||
end | ||
end | ||
|
||
def destroy_keep_alive | ||
@heartbeat.stop | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Hector | ||
class Heartbeat | ||
def self.create_timer(interval, &block) | ||
EventMachine::PeriodicTimer.new(interval, &block) | ||
end | ||
|
||
def initialize(interval = 60, &block) | ||
@interval, @block = interval, block | ||
start | ||
end | ||
|
||
def start | ||
@timer ||= self.class.create_timer(@interval) { pulse } | ||
end | ||
|
||
def pulse | ||
@block.call | ||
end | ||
|
||
def stop | ||
@timer.cancel | ||
@timer = nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require "test_helper" | ||
|
||
module Hector | ||
class KeepAliveTest < IntegrationTest | ||
test :"keep-alive ping is sent on pulse" do | ||
authenticated_connection.tap do |c| | ||
assert_not_sent_to c, "PING hector.irc" | ||
assert_sent_to c, "PING hector.irc" do | ||
pulse(c) | ||
end | ||
assert !c.connection_closed? | ||
end | ||
end | ||
|
||
test :"responding with pong results in another ping on the next pulse" do | ||
authenticated_connection.tap do |c| | ||
pulse(c) | ||
c.receive_line "PONG hector.irc" | ||
assert_sent_to c, "PING hector.irc" do | ||
pulse(c) | ||
end | ||
assert !c.connection_closed? | ||
end | ||
end | ||
|
||
test :"not responding with pong results in disconnection on the next pulse" do | ||
authenticated_connection.tap do |c| | ||
pulse(c) | ||
assert_not_sent_to c, "PING hector.irc" do | ||
pulse(c) | ||
end | ||
assert c.connection_closed? | ||
end | ||
end | ||
|
||
test :"channel members are notified of keep-alive timeouts" do | ||
authenticated_connections(:join => "#test") do |c1, c2| | ||
pulse(c1) | ||
assert_sent_to c2, ":user1!sam@hector.irc QUIT" do | ||
pulse(c1) | ||
end | ||
end | ||
end | ||
|
||
def pulse(connection) | ||
heartbeat(connection).pulse | ||
end | ||
|
||
def heartbeat(connection) | ||
connection.session.instance_variable_get(:@heartbeat) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Hector | ||
class Heartbeat | ||
def self.create_timer(interval) | ||
Object.new.tap do |o| | ||
def o.cancel; end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters