[Twisted-Python] regarding ticket #2328

2012-01-19 Thread moses dsouza
Hi

Can anyone provide any ideas how to get started on this one ? Is this still
open ?

regards
moijes12
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] Finding out the IP which it failed to connect

2012-01-19 Thread Facundo Batista
I have some code that uses a twisted.web.client.HTTPClientFactory.

I've found that because some issues (firewall rules, not relevant to
the problem), I experienced failures to connect.

More specifically, I told it to connect to one particular address, and
because of DNS load distribution, that address converted to several
different IPs, and one of that IPs was not open, so it failed to
connect with a TCPTimedOutError (code 110).

When it failed to connect, it executed the "clientConnectionFailed"
method of HTTPClientFactory, which receives a
twisted.internet.tcp.Connector instance, and the reason of the
failure.

The question is: Is there a way, at that point (when
clientConnectionFailed is called), to find out *to which IP* it failed
to connect?

Thank you very much!

-- 
.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] for reference - how to get ssl certificate from a xmlrpc function

2012-01-19 Thread Hanusz L .
I had some difficulty to find how to get the ssl certificate from the xmlrpc 
function but I found how to do it :
You can get the protocol from the xmlrpc function with @withRequest
http://twistedmatrix.com/documents/11.1.0/api/twisted.web.xmlrpc.withRequest.html
Then you can use getPeerCertificate from the transport

@withRequest
def xmlrpc_helloworld(self,request):
return 'Hello ' +  
request.channel.transport.getPeerCertificate().get_subject().commonName


#
This e-mail message has been scanned for Viruses and Content and cleared 
by Mailsecurity software
#
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] xmlrpc function return message to client asynchronously

2012-01-19 Thread Hanusz L .

I'd like to create a xmlrpc function get_message with the following 
characteristic : 
 - If the server doesn't have any message to send the client, the server will 
answer with a timeout after 60s (and the client can retry)
 - If the server has a message to send to the client, the answer is sent 
directly

To do that, can I do the following:
- create a deferred in the xmlrpc function with a calllater of 60s and keep a 
reference to this deferred in the factory
  * If the server has no message to send, the deferred will be called by the 
reactor and answer a timeout
 * If the server has a message to send, it will call the deferred in his own 
code (with a parameter ?) before the reactor and answer the message.

Is it possible to call a deferred before the reactor like this ?

Thanks.
Leszek
#
This e-mail message has been scanned for Viruses and Content and cleared 
by Mailsecurity software
#

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] xmlrpc function return message to client asynchronously

2012-01-19 Thread Tristan Seligmann
On Thu, Jan 19, 2012 at 6:41 PM, Hanusz L.  wrote:
>
> I'd like to create a xmlrpc function get_message with the following 
> characteristic :
>  - If the server doesn't have any message to send the client, the server will 
> answer with a timeout after 60s (and the client can retry)
>  - If the server has a message to send to the client, the answer is sent 
> directly
>
> To do that, can I do the following:
> - create a deferred in the xmlrpc function with a calllater of 60s and keep a 
> reference to this deferred in the factory
>  * If the server has no message to send, the deferred will be called by the 
> reactor and answer a timeout
>  * If the server has a message to send, it will call the deferred in his own 
> code (with a parameter ?) before the reactor and answer the message.

The object returned by callLater() provides the IDelayedCall[1]
interface. If you keep a reference to this object as well as the
deferred, then you can cancel the call when you return a response by
calling the .cancel() method.

[1] 
http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IDelayedCall.html
-- 
mithrandi, i Ainil en-Balandor, a faer Ambar

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] regarding ticket #2328

2012-01-19 Thread Glyph

On Jan 19, 2012, at 7:21 AM, moses dsouza wrote:

> Hi
> 
> Can anyone provide any ideas how to get started on this one ?


Talking to Ralph Meijer (are you listening, Ralph?) would be a good place to 
get started.

Also, http://twistedmatrix.com/trac/ticket/2320 ("s2s") is (if I understand 
correctly) a prerequisite for a useful jabber implementation, otherwise you 
won't be able to talk to people on other hosts.

Other than that, just reading some relevant XEPs 
() and implementing any 
functionality that is missing from twisted.words.

> Is this still open ?

Yes, absolutely.  Not only is it open, it is a critical missing piece of 
twisted.words, in my opinion.  Thanks for looking at it, please feel free to 
keep posting to this list with more questions if you need any help.

-glyph


___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] regarding ticket #2328

2012-01-19 Thread Yaroslav Fedevych
I, for one, second the question.

What I'm currently missing is even the basic information on what, more 
exactly, Twisted Words is and what it is not. Recently, I heard some 
potential customer talking about a universal messaging gateway (multiple 
protocols (including email), throttling, in some cases — per-message 
charging, messaging storage). I was wondering if t.words is something 
which is exactly right to use for projects like that and what facilities 
it provides to help me.

Currently I see it is mostly client-oriented. I can only see an IRC 
protocol (server-side), I however don't see what interfaces I need to 
implement for a working pluggable messaging server. Maybe I'm looking at 
wrong places or misunderstand the purpose of t.words altogether.

-- 
Yaroslav Fedevych
jaroslaw.fedew...@gmail.com
Custom networked sofware solutions
tel. +380685061839
  +48222472352
Skype: jaroslaw.fedewicz

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] questions about testing xmlrpc server with ssl - problems with more than 1000 requests

2012-01-19 Thread Hanusz L .
I did some testing between a twisted xmlrpc ssl server and a twisted client 
with lots of simultaneous requests.
I'm using windows (don't have the choice...), python 2.7, twisted 11.1 and both 
server and client are on the same computer... (Xeon 2Ghz 3GB of RAM)

The client is configured to get a number of "Hello" answers and if there is a 
problem on the connection, it will try again with a calllater of 1second

If the number of requests is low (<100), there is no problem.
With 200 requests, there is some errors "Connection to the other side was lost 
in a non-clean fashion." but the client can still get all the answers by 
retrying.
If I try to increase the number of requests, the number of retries is rising 
very fast and at some point the client is unable to get any answer (with errors 
like "User timeout caused connection failure")
100 request - no retries 0.688 s
200 requests - 37 retries 1.5s
500 requests - 395 retries 4.2s
750 requests - 1205 retries  - 36.4s
1500 requests - too much

In the client the time is measured between the start of the reactor and the 
reception of each answer.

 What I don't understand is that it seems no answer is parsed before all the 
messages are received. 
For example for the 750 requests, the first message is parsed after 32.1s

My questions are the following:
- what is happening ?
- why are all messages parsed at the end ? Priority of the reactor ?
- is it possible to limit the number of incoming connections globally and/or 
for each client ? How ? Same for outgoing connections in the client.
- to be able to see what is going on, is it possible to print the number of 
connections (counting connectionMade and connectionLost or is there a better 
method?), and the number of callbacks waiting in the reactor ?
- is there a maximum number of callbacks waiting in the reactor ?

The code I used is below.
Modified from 
http://twistedmatrix.com/pipermail/twisted-python/2007-May/015357.html

Thanks for your help.

##
xmlrpc_ssl_helloworld_server.py
##

from twisted.web import xmlrpc, server, http
from twisted.internet import reactor, ssl
from twisted.web.xmlrpc import withRequest

class Engine:
def __init__(self):
self.clientWS_ip_address = "127.0.0.1"
self.clientWS_port = 8010
self.clientWS = 
ClientWebServiceListener(self.clientWS_ip_address,self.clientWS_port,self)
self.clientWS.start()

class ClientWebServiceListener():

class XmlRpcFunctions(xmlrpc.XMLRPC):

@withRequest
def xmlrpc_helloworld(self,request):
return 'Hello ' +  
request.channel.transport.getPeerCertificate().get_subject().commonName

def __init__(self,ip_address,port,engine):
self.engine = engine
self.ip_address = ip_address
self.port = port

def start(self):
ctx = self.makeSSLContext(myKey='server.pem',trustedCA='cacert.pem')
self.listening_port = reactor.listenSSL(self.port, 
server.Site(self.XmlRpcFunctions()) ,ctx)

def makeSSLContext(self,myKey,trustedCA):
'''Returns an ssl Context Object
@param myKey a pem formated key and certificate with for my current host
the other end of this connection must have the cert from the CA that 
signed this key
@param trustedCA a pem formated certificat from a CA you trust
you will only allow connections from clients signed by this CA
and you will only allow connections to a server signed by this CA
'''
fd = open(myKey,'r')
theCert = ssl.PrivateCertificate.loadPEM(fd.read())
fd.close()
fd = open(trustedCA,'r')
theCA = ssl.Certificate.loadPEM(fd.read())
fd.close()
ctx = theCert.options(theCA)

 # Now the options you can set look like Standard OpenSSL Library options

 # The SSL protocol to use, one of SSLv23_METHOD, SSLv2_METHOD,
 # SSLv3_METHOD, TLSv1_METHOD. Defaults to TLSv1_METHOD.
ctx.method = ssl.SSL.TLSv1_METHOD

 # If True, verify certificates received from the peer and fail
 # the handshake if verification fails. Otherwise, allow anonymous
 # sessions and sessions with certificates which fail validation.
ctx.verify = True

 # Depth in certificate chain down to which to verify.
ctx.verifyDepth = 1

 # If True, do not allow anonymous sessions.
ctx.requireCertification = True

 # If True, do not re-verify the certificate on session resumption.
ctx.verifyOnce = True

 # If True, generate a new key whenever ephemeral DH parameters are used
 # to prevent small subgroup attacks.
ctx.enableSingleUseKeys = True

 # If True, set a session ID on each context. This allows a shortened
 # handshake to be used when a known client reconnects.
ctx.enableSessions = True

 # If True, enable various non-spec protocol fixes for broken
 # SSL implementations.
ctx.fixBrokenPeer

Re: [Twisted-Python] regarding ticket #2328

2012-01-19 Thread Glyph

On Jan 19, 2012, at 1:07 PM, Yaroslav Fedevych wrote:

> I, for one, second the question.
> 
> What I'm currently missing is even the basic information on what, more 
> exactly, Twisted Words is and what it is not. Recently, I heard some 
> potential customer talking about a universal messaging gateway (multiple 
> protocols (including email), throttling, in some cases — per-message 
> charging, messaging storage). I was wondering if t.words is something 
> which is exactly right to use for projects like that and what facilities 
> it provides to help me.

There is no authoritative statement about what twisted.words is not because 
twisted.words is incomplete.  You can definitely use it for servers, and many 
people do.

> Currently I see it is mostly client-oriented. I can only see an IRC 
> protocol (server-side), I however don't see what interfaces I need to 
> implement for a working pluggable messaging server. Maybe I'm looking at 
> wrong places or misunderstand the purpose of t.words altogether.

All of the facilities for parsing the client side of an XMPP connection also 
work for the server side.  And twisted.words does currently have some 
facilities for dealing with servers, such as 'twistd xmpp-router'.

You may be interested in several extensions to twisted.words.  Wokkel, 
especially, is hopefully going to be included in twisted.words itself at some 
point: .  Idavoll provides publish/subscribe 
functionality on top of wokkel and twisted.words: .  
Palaver provides a multi-user chat component: 
 - however, most of the links to the 
original sites for Palaver appear to be dead now, so I gather that project has 
stopped development.

Ultimately, what you have to keep in mind is that twisted.words, like all of 
Twisted, is an open source project and not a commercial product.  If you would 
like it to do more than it does, please contribute code to help it grow into a 
full-featured XMPP solution.

-glyph___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python