This project was migrated from https://code.google.com/p/p2p-sip on May 17, 2015
Keywords: SIP, P2P, Python, p2psip, DHT, implementation
Members: kundan10 (owner, copyright holder), theintencity (owner, copyright holder), rami.halloush, luke.weber, voipresearcher, juanantonio.ram
Links: Blog, 39 peers, Implementing SIP telephony in Python, Student Projects, Support
License: GNU GPL v3
Others: starred by 36 users
This project aims at implementing an open-source peer-to-peer Internet telephony software using the Session Initiation Protocol (P2P-SIP) in the Python programming language.
New: The new RTClite project is a superset of this P2P-SIP project. Please migrate to or start using the RTClite project instead of this. More information at https://github.com/theintencity/rtclite
New: project description has been moved from the 39peers.net website to this page
Peer-to-peer systems inherently have high scalability, fault tolerance and robustness against catastrophic failures because there is no central server and the network self-organizes itself. Internet telephony can be an application of peer-to-peer architecture where the participants locate and communicate with each other without relying on expensive or managed service providers. This project is an attempt to provide an open source peer-to-peer software based on open standards.
This project is developed for student developers and researchers to experiment with new ideas. It is written in Python programming language. It supports open protocols such as IETF SIP and RTP. It is licensed under GNU/GPL license (an alternate commercial license is available as well). This project does not use the recommendation developed by the IETF P2P-SIP working group. I am looking for student volunteers to contribute in that regard.
Please use the git clone to get the sources. Alternatively, you can download the latest tar/gzip archive from the download page. Or you can browse the source code with documentation extracted from the corresponding specifications online here. The annotated source code for web view is generated using the included tool htmlify.py
.
The downloaded archive will create the p2p-sip/
directory containing the source code in Python. The sub-directory src/
contains the source code packages app
, std
, tools
and external
.
The std
package contains implementation of various IETF RFCs and Internet-drafts such as RFC 3261, RFC 3550, RFC 2617, etc. The app
package contains the applications such as SIP client (voip.py
), DHT using Bamboo (dht.py
), etc. Some of the other modules are not yet completed.
You will need Python 2.5 or higher (but not Python 3.x) to run the software. Set your python path and test a couple of modules such as voip
and dhtgui
before modifying the source code for your needs.
You need to set the PYTHONPATH
environment variable before testing these modules. For example, you can do the following to test the voip
module. It performs certain SIP registration, call and instant message test with the iptel.org
server.
bash$ tar -zxvf source-*.tgz
bash$ cd p2p-sip/src
bash$ export PYTHONPATH=.:external:std:app
bash$ python app/voip.py
Each module comes with a simple test case to test that module. I will upload more example applications built using these basic modules as demanded. The following command launches a test user interface for the P2P module. It depends on wxPython
for user interface functions.
bash$ python app/dhtgui.py
This launches a user interface with a DHT circle. You can click near the center of the circle to add a new node.
Alternatively, to launch the P2P-SIP node, use the p2psip.py
module as follows. The first node should be launched with -s
option to become a super-node, and all subsequent ones should be launched without -s
to join this P2P network. The first node listens on SIP port 5062. If you use -d
option then you can also see the P2P messages exchanged between these nodes. If you wish to run the P2P network across multiple IP networks, you will need to re-configure the boot-strap node because the multicast discovery typically works only within the same IP network.
bash$ python app/p2psip.py -s # first node as boot strap server
bash$ python app/p2psip.py # subsequent nodes on other terminals/machines
If you wish to test P2P-SIP using X-lite please use the following X-lite v3 configuration. In preferences/options under "Account" tab, select "Domain proxy" and set the proxy address to be the boot strap server on port 5062, or one of the other server with correct port, e.g., 127.0.0.1:5062
. In "Voicemail" tab, uncheck everything to avoid sending unnecessary voicemail related messages to P2P-SIP nodes. In "Topology" tab, under "Firewall traversal", the "IP address" is set to "Use local IP address". "STUN server" is set to "Use specified server" and the address is left blank. Uncheck all other boxes and set "Use Xtunnels" to never. In "Presence" tab, the "Mode" is peer-to-peer. All other values are left as default. In "Advanced" tab, make sure to uncheck the "send SIP keep alive messages". In fact, the only checked box is the "use rport". All other values are left as default.
Beyond these examples, feel free to explore the source code and learn more about various modules.
If you have patch for a bug-fix or a feature, feel free to send me the patch to the support group. If you plan to do significant contributions, please let me know and I will add you as a project member so that you can check in files using SVN. Please join the support group if you want to contribute or hear about the project announcements.
If you are a project student and would like to do a project in SIP, P2P or P2P-SIP, you are welcome to use this software. I will be happy to assist you in mentoring your project in my free time. One of the main objective of the project is to help the student developers understand the existing protocols for peer-to-peer and real-time communication. Thus we encourage developers to take a look at the source code and how it reflects the specifications of various protocols. The Python programming language allows us to write compact and concise software in a way that provides pseudo-code to validate the specifications. You can browse the source code with embedded comments from corresponding specifications later on this page.
All individual contributors who would like to add a feature, fix a bug or modify the source code in any way, are welcome! Please follow the programming style and send your modified source code to us, and we will add it after review. All submitted code must be released under GNU/GPL, but the original author retains the Copyright.
Notice: The past and current owner of this project is Kundan Singh. The owners of the project reserve all the rights to source code. All the contributors and committers automatically and implicitly assign all the rights to the owners by contributing to this project. The rights assignment implies that the owners reserve all the rights to publish or distribute the sources or binaries elsewhere under another license for commercial or non-commercial use. Irrespective of the rights, this project will continue to remain open source.
Please follow these high-level guidelines:
htmlify.py
tool available in this software to beautify and decorate your RFC implementation.Beyond these, you can use your own style and discretion to design your software.
There are two parts in the software -- the standards and applications. The standards as specified in certain RFCs and Internet-drafts are implemented in the std
package whereas the high-level applications are implemented in the app
package. As mentioned earlier, one of the main advantage of building on this project is that the source code is much smaller in terms of lines of code.
The following table summarizes the std
package content and allows your to browse the source code with embedded documentation extracted from the corresponding specifications.
Module | Description | Lines |
---|---|---|
rfc2198 | Implements RTP payload type for redundant audio data. | 45 |
rfc2396 | Implements various forms of addresses such as URI or SIP address | 177 |
rfc2617 | Implements HTTP basic and digest authentication which is reused in SIP. | 131 |
rfc2833 | Implements the DTMF touch-tone payload in a RTP packet. | 40 |
rfc3261 | Implements the user agent part of Session Initiation Protocol (SIP). | 1558 |
rfc3263 | Implements SIP server discovery using DNS NAPTR, SRV and A. | 108 |
rfc3264 | Implements the SDP offer answer model for unicast session as used in SIP | 120 |
rfc3489bis | Implements basic NAT traversal technologies such as STUN, NAT discovery using STUN, and variation on TURN. | 693 |
rfc3550 | Implements the Real-time Transport Protocol (RTP) and its companion control protocol RTCP. | 687 |
rfc3551 | Defines the static payload types for RTP. | 48 |
rfc3920 | Implements XMPP core for client. | 435 |
rfc3921 | Implements IM and Presence of XMPP client (incomplete). | 373 |
rfc4566 | Implements the session description protocol (SDP). | 162 |
The high level application modules use some of these modules and build additional applications or libraries as summarized below:
Module | Description | Lines |
---|---|---|
voip | Implements a SIP user agent library for registration, call, instant messaging and conferences. | 1261 |
dht | Implements a variation of the Bamboo/Pastry distributed hash table algorithm | 1983 |
opendht | Implements the client side library to connect to existing OpenDHT service. | 71 |
p2p | Implements a peer-to-peer pipe abstraction between two peers using a DHT. (incomplete). | 642 |
p2psip | Implements various P2P-SIP application scenarios using p2p and voip modules. (incomplete). | 285 |
crypto | Implements an abstraction for cryptography algorithms to be used in dht or p2p. (incomplete). | 261 |
dhtgui | Implements a test tool to launch p2p/dht module and display the nodes in a circle. | 427 |
sipd | Implements a very simple SIP registration and proxy server using rfc3261 module. (incomplete) | 115 |
There are several supporting modules. Below are some of the important ones.
Module | Description | Lines |
---|---|---|
simplexml | Implements a simple XML DOM with convenient methods and operators to work on XML and XMLList. | 420 |
You can also browse the sources but without the embedded documentation.
I have used several types of documentation in this project to assist the student developers understand the software.
This project is free-for-all to use. The software that enables peer-to-peer protocol is released under GNU/GPL. All the content and data, are Copyright 2007-2014 by Kundan Singh.
If you want to distribute, copy or modify this software, you are welcome to do so under the terms of the GNU General Public License. If you are unfamiliar with this license, you might want to read How To Apply These Terms To Your Program and the GNU General Public License FAQ.
An alternative commercial license is available. Please contact us by email.
There are a number of existing peer-to-peer (P2P) software applications. Most applications are targeted for file sharing that uses caching of popular content for efficiency. There are a few distributed hash table (DHT) based applications as well that are more suited for Internet telephony. However, many of these existing systems suffer from one or more of the following drawbacks:
There are some remarkably great software applications that fill in part of the picture. For example Benny's pjsip.org provides a very fine high performance, small footprint library for SIP, RTP, media, NAT traversal, etc. JAIN NIST stack for SIP has been used extensively in several projects. Sean's Bamboo DHT provides a open source Java based DHT implementation. The project goals of these projects are different from ours. In particular, we advise you to not use our software if you are interested in high performance, embedded platform or well tested piece of engineering.
Goals of this project:
Our project is meant as experimental for developers (hint: project students) to quickly try out new ideas, without having to write thousands of lines of code or without spending a lot of time to see if a small variation in the existing algorithm works well.
Another main goal of the project is to help the developers understand the RFCs and drafts of various protocols and how they translate into source code. This helps developing more inter-operable software easily. Usually a developer has to translate the specification into object oriented design and pseudo-code, and then write the implementation. This project provides design of several specifications in Python which is a pseudo-code style language.
Python encourages developers' efficiency because of very compact, concise (and beautiful!) software that one can write. Based on my experience the number of lines-of-code is 5 to 30 times less than the corresponding code in Java or C/C++.
I have written SIP stack four times now in four different languages. First was a modification of a C stack based on RFC 2543 in 1999-2000. Later I reworked the user agent API and the library to create a RFC 3261 based C++ stack in 2002, with some C code hanging around. After graduating and joining a company, I wrote another SIP stack in ActionScript
, which is like ECMAScript
, in 2006. And finally I wrote again for this project in Python end of 2007. The first time it took around 4-5 months to get things going in C, then around 3-4 months for C++, around one month in ActionScript
and about a week in Python. Based on my experience, generally for every line of Python code there is about 3-10 lines of ActionScript
code, 5-10 lines of Java code, and more than 20 lines in C.
The source code for RFC 3261 implementation in Python for user agents is about 1300 lines, whereas a similar library in C++ or Java extends to more than ten thousand lines of source code. For a significantly large project, if designed right, one can achieve a factor of improvement in lines-of-code. Clearly writing one line of Python code takes more time than writing one line of Java code, but reducing the overall lines-of-code has many fold advantages:
I have written many large software pieces in many different programming languages, C, C++, Tcl, Perl, Java, ActionScript
and Python. And I have come to a conclusion that Python is probably the best, and should be used for all applications if possible. Projects where Python may not be used are those which have specific constraints such as low level access or performance requirements (C/C++), or need to work within a browser (JavaScript
) or server (PHP).
This article lists other projects that use software pieces from this project. The list includes SIP-RTMP gateway and the Internet video city. If you (plan to) use some pieces of this project, please let me know so that I can list your project on this page.
crypto
module that implements publilc key cryptography.