Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
irker
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iDB
irker
Commits
c2ec8582
Commit
c2ec8582
authored
Aug 30, 2012
by
Eric S. Raymond
Browse files
Options
Downloads
Patches
Plain Diff
Set deaf mode to reduce bandwidth usage.
parent
c2a8ddbe
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
irker.py
+19
-12
19 additions, 12 deletions
irker.py
with
19 additions
and
12 deletions
irker.py
+
19
−
12
View file @
c2ec8582
...
@@ -18,8 +18,6 @@ version and exits.
...
@@ -18,8 +18,6 @@ version and exits.
Requires Python 2.6 and the irc.client library at version >= 2.0.2: see
Requires Python 2.6 and the irc.client library at version >= 2.0.2: see
http://sourceforge.net/projects/python-irclib
http://sourceforge.net/projects/python-irclib
TO-DO: set deaf usermode.
"""
"""
# These things might need tuning
# These things might need tuning
...
@@ -45,11 +43,12 @@ version = "1.0"
...
@@ -45,11 +43,12 @@ version = "1.0"
#
#
# One Irker object manages multiple IRC sessions. It holds a map of
# One Irker object manages multiple IRC sessions. It holds a map of
# Dispatcher objects, one per (server, port) combination, which are
# Dispatcher objects, one per (server, port) combination, which are
# responsible for routing messages to one of any
b
umber of Connection
# responsible for routing messages to one of any
n
umber of Connection
# objects that do the actual socket conversation. The reason for
# objects that do the actual socket conversation
s
. The reason for
# the Dispatcher layer is that IRC daemons limit the number of channels
# the Dispatcher layer is that IRC daemons limit the number of channels
# a client (that is, from the daemon's point of view, a socket) can be
# a client (that is, from the daemon's point of view, a socket) can be
# joined to.
# joined to, so we may need a flock of connection instances each with
# its own socket.
#
#
# Connections are timed out and removed when either they haven't seen a
# Connections are timed out and removed when either they haven't seen a
# PING for a while (indicating that the server may be stalled or down)
# PING for a while (indicating that the server may be stalled or down)
...
@@ -67,7 +66,7 @@ version = "1.0"
...
@@ -67,7 +66,7 @@ version = "1.0"
# problem - there is little point in delivery to a relay that is down or
# problem - there is little point in delivery to a relay that is down or
# unreliable.
# unreliable.
class
Connection
(
irc
.
client
.
ServerConnection
)
:
class
Connection
:
def
__init__
(
self
,
irker
,
servername
,
port
):
def
__init__
(
self
,
irker
,
servername
,
port
):
self
.
irker
=
irker
self
.
irker
=
irker
self
.
servername
=
servername
self
.
servername
=
servername
...
@@ -82,8 +81,10 @@ class Connection(irc.client.ServerConnection):
...
@@ -82,8 +81,10 @@ class Connection(irc.client.ServerConnection):
self
.
queue
=
Queue
.
Queue
()
self
.
queue
=
Queue
.
Queue
()
self
.
thread
=
threading
.
Thread
(
target
=
self
.
dequeue
)
self
.
thread
=
threading
.
Thread
(
target
=
self
.
dequeue
)
self
.
thread
.
start
()
self
.
thread
.
start
()
def
nickname
(
self
,
n
):
def
nickname
(
self
,
n
=
None
):
"
Return a name for the nth server connection.
"
"
Return a name for the nth server connection.
"
if
n
is
None
:
n
=
self
.
nick_trial
return
(
NAMESTYLE
%
n
)
return
(
NAMESTYLE
%
n
)
def
handle_ping
(
self
):
def
handle_ping
(
self
):
"
Register the fact that the server has pinged this connection.
"
"
Register the fact that the server has pinged this connection.
"
...
@@ -91,12 +92,12 @@ class Connection(irc.client.ServerConnection):
...
@@ -91,12 +92,12 @@ class Connection(irc.client.ServerConnection):
def
handle_welcome
(
self
):
def
handle_welcome
(
self
):
"
The server says we
'
re OK, with a non-conflicting nick.
"
"
The server says we
'
re OK, with a non-conflicting nick.
"
self
.
status
=
"
ready
"
self
.
status
=
"
ready
"
self
.
irker
.
debug
(
1
,
"
nick %s accepted
"
%
self
.
nickname
(
self
.
nick_trial
))
self
.
irker
.
debug
(
1
,
"
nick %s accepted
"
%
self
.
nickname
())
def
handle_badnick
(
self
):
def
handle_badnick
(
self
):
"
The server says our nick has a conflict.
"
"
The server says our nick has a conflict.
"
self
.
irker
.
debug
(
1
,
"
nick %s rejected
"
%
self
.
nickname
(
self
.
nick_trial
))
self
.
irker
.
debug
(
1
,
"
nick %s rejected
"
%
self
.
nickname
())
self
.
nick_trial
+=
1
self
.
nick_trial
+=
1
self
.
nick
(
self
.
nickname
(
self
.
nick_trial
))
self
.
nick
(
self
.
nickname
())
def
enqueue
(
self
,
channel
,
message
):
def
enqueue
(
self
,
channel
,
message
):
"
Enque a message for transmission.
"
"
Enque a message for transmission.
"
self
.
queue
.
put
((
channel
,
message
))
self
.
queue
.
put
((
channel
,
message
))
...
@@ -118,7 +119,7 @@ class Connection(irc.client.ServerConnection):
...
@@ -118,7 +119,7 @@ class Connection(irc.client.ServerConnection):
try
:
try
:
self
.
connection
.
connect
(
self
.
servername
,
self
.
connection
.
connect
(
self
.
servername
,
self
.
port
,
self
.
port
,
nickname
=
self
.
nickname
(
self
.
nick_trial
),
nickname
=
self
.
nickname
(),
username
=
"
irker
"
,
username
=
"
irker
"
,
ircname
=
"
irker relaying client
"
)
ircname
=
"
irker relaying client
"
)
self
.
status
=
"
handshaking
"
self
.
status
=
"
handshaking
"
...
@@ -222,7 +223,7 @@ class Irker:
...
@@ -222,7 +223,7 @@ class Irker:
self
.
irc
.
add_global_handler
(
"
nicknameinuse
"
,
self
.
_handle_badnick
)
self
.
irc
.
add_global_handler
(
"
nicknameinuse
"
,
self
.
_handle_badnick
)
self
.
irc
.
add_global_handler
(
"
nickcollision
"
,
self
.
_handle_badnick
)
self
.
irc
.
add_global_handler
(
"
nickcollision
"
,
self
.
_handle_badnick
)
self
.
irc
.
add_global_handler
(
"
unavailresource
"
,
self
.
_handle_badnick
)
self
.
irc
.
add_global_handler
(
"
unavailresource
"
,
self
.
_handle_badnick
)
#
self.irc.add_global_handler("featurelist", self._handle_features)
self
.
irc
.
add_global_handler
(
"
featurelist
"
,
self
.
_handle_features
)
thread
=
threading
.
Thread
(
target
=
self
.
irc
.
process_forever
)
thread
=
threading
.
Thread
(
target
=
self
.
irc
.
process_forever
)
self
.
irc
.
_thread
=
thread
self
.
irc
.
_thread
=
thread
thread
.
start
()
thread
.
start
()
...
@@ -246,6 +247,12 @@ class Irker:
...
@@ -246,6 +247,12 @@ class Irker:
"
Nick not accepted for this connection.
"
"
Nick not accepted for this connection.
"
if
connection
.
context
:
if
connection
.
context
:
connection
.
context
.
handle_badnick
()
connection
.
context
.
handle_badnick
()
def
_handle_features
(
self
,
connection
,
event
):
"
Determine if and how we can set deaf mode.
"
if
connection
.
context
:
for
lump
in
event
.
arguments
():
if
lump
.
startswith
(
"
DEAF=
"
):
connection
.
mode
(
connection
.
context
.
nickname
(),
"
+
"
+
lump
[
5
:])
def
drop_server
(
servername
,
port
):
def
drop_server
(
servername
,
port
):
"
Drop a server out of the server map.
"
"
Drop a server out of the server map.
"
del
self
.
servers
[(
servername
,
port
)]
del
self
.
servers
[(
servername
,
port
)]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment