diff --git a/torchat/doc/howto_mac_osx.html b/torchat/doc/howto_mac_osx.html deleted file mode 100644 index e69de29b..00000000 diff --git a/torchat/doc/howto_mac_osx.md b/torchat/doc/howto_mac_osx.md new file mode 100644 index 00000000..26363600 --- /dev/null +++ b/torchat/doc/howto_mac_osx.md @@ -0,0 +1,211 @@ +# Installation / Usage Instructions for TorChat on Mac OS X # + +***WARNING: THESE INSTRUCTIONS CURRENTLY HAVE BEEN TESTED ONLY ON MAC OS X + VERSION 10.8. ALL OTHER VERSIONS USE CAUTION.*** + +## Download and Install Tor ## + +Unfortunately, TorChat currently requires a `tor` executable in order to +function. This severely complicates the install, as the Tor project +tries to helpfully package Tor into a one-stop bundle for browsing the +web. + +There are three ways in which to install Tor on Mac OS X: downloading +a pre-built image from upstream TorProject, installing through +[MacPorts](https://www.macports.org/), or building from upstream +TorProject source. + +### Web Package Download ### + +If you're not running MacPorts (if you don't know what that is, you're +not running it), go +[here](https://www.torproject.org/download/download.html.en#apple) and +download either the i686 version (32-bit) or x86_64 (64-bit) version. +If you're not sure which one you need, go with the i686 (32-bit) +version. + +This will create a file in your downloads folder with a name like +**TorBrowser-2.3.25-10-osx-x86_64-en-US.zip**. If it doesn't create +an application with a name like **TorBrowser_en-US** as well, +double-click on the aforementioned file. An application named +**TorBrowser_en-US** should now appear. Move the **TorBrowser_en-US** +file into your Applications folder. + +The key to installing this way is that there is a `tor` executable +within the **TorBrowser_en-US** application. + +### MacPorts ### + +If you already have MacPorts installed, you can simply use the command: + + $ sudo port install tor torsocks + +and Tor will be installed, regardless of platform. + +This method creates a `tor` executable wherever your MacPorts is set +to install to (typically */opt/local/tor*). + +### Building from Upstream Source ### + +Source can be found +[here](https://www.torproject.org/download/download.html.en#source). +I recommend using the stable version. Build instructions can also be +found in that location. + +## Download and Install Python 2.x ## + +If you're using Mac OS X 10.8, you're in luck! Python 2.7 comes by +default. + +TODO: other versions of Mac OS X. Need at least Python 2.6 for +wxPython (unless MacPorts deals with earlier versions). + +## Download and Install wxPython 2.x ## + +Which wxPython you use will depend on which Python you are using. If +you installed Python from MacPorts, you should also install wxPython +from MacPorts; if you downloaded a binary of Python or used the +built-in Mac OS Python, you should download a binary of wxPython; and +if you want to build things from source, follow the instructions below. + +### Download a Pre-Built Binary ### + +Pre-built binaries can be found +[here](http://wxpython.org/download.php#stable). I cannot think of a +reason to use the binaries with "ansi" in their names. You should use +the version of wxPython appropriate to your Python installation (so, +for example, if you're using Python 2.7, you will want the link +**wxPython2.8-osx-unicode-py2.7**, or for Python 2.6, you would want +**wxPython2.8-osx-unicode-py2.6**). + +When you download the appropriate wxPython, a disk image should be +mounted (with a name like +**wxPython2.8-osx-unicode-2.8.12.1-universal-py27**). If it is not, +check your Downloads folder for a file with name like +**wxPython2.8-osx-unicode-2.8.12.1-universal-py2.7.dmg** and +double-click it. + +In the disk image, there will be an installer named something like +**wxPython2.8-osx-unicode-universal-py2.7.pkg**. Double-click it, and +the installer will begin. + +Click "Continue" to begin the installation, read the Software License +Agreement (click "Continue", then "Agree" when done if and only if you +agree to abide by it), then click "Install". (You may be prompted for +a password at this point.) When the installation finishes, click +"close" on the installer. + +### MacPorts ### + +(TODO: once bug is resolved, write up how to do this) + +### Building from Source ### + +It's important to note that the benefit here is not from building +Python binaries (because Python binaries aren't a thing), but from +building wxWidgets from source. Anyway, take a deep breath, +reconsider your life choices, and follow the instructions +[here](http://wxpython.org/builddoc.php). + +## TorChat ## + +For purposes of this guide, we will install torchat-source, which is a +source release of TorChat. It is also totally workable to substitute +another version from git instead; however, it is assumed that if you +do this, you know what you are doing. + +Releases can be downloaded +[here](https://github.com/prof7bit/TorChat/downloads). You probably +want to download the highest entry whose name resembles +**torchat-source-0.9.9.553.zip**. + +This will create a file in your Downloads folder with name something +like **torchat-source-0.9.9.553.zip**. If it does not also create a +folder with name like **torchat-source-0.9.9.553**, double click on +the aforementioned file and it should appear. + +Okay, so now we're going to launch TorChat. Take a deep breath, and +let's make a launcher. Open TextEdit (or the text editor of your +choice). Ensure the document is plain text by going to the "Format" +menu. If you see an option "Make Plain Text", choose it; otherwise, +your document is already plain text so don't select anything. Type +the following: + + #!/bin/bash + PATH=/Applications/TorBrowser_en-US.app/Contents/MacOS:$PATH + arch -i386 python ~/Downloads/torchat-source-*/src/torchat.py & + exit + +Be sure to leave a blank line at the end of the file, then save it on +the Desktop (or Applications folder or anywhere you like) with a +clever name (I like **TorChat Launcher**, myself). When saving, be +sure to uncheck the box that says "If no extension is provided, use +'.txt'.", and also ensure that there are no periods ('.') in the name +that you save it as. + +Select the file you just made in the finder. Then open +**Terminal.app** (it can be found in the **Utilities** folder in your +**Applications** folder). Type `chmod +x ` (with a space at the end) +and then, *before hitting enter*, drag your TorChat launcher into the +Terminal.app window. Then press the Return key. You should see the +icon of your launcher change in the Finder. + +Simply double-click on the launcher to launch TorChat. After a +moment, another window will open: your TorChat contact list! + +## Upgrading components ## + +All components of the setup we just made are upgradable. Here's how: + +### Tor ### + +If you installed Tor through the TorBrowser pre-built binary, update +as instructed by TorProject. Your TorChat launcher will continue to +work. + +If you installed Tor through MacPorts, `sudo port upgrade tor +torsocks` will automatically update you, and your TorChat launcher +will continue to work. + +If you built Tor from source, you will need to rebuild and re-install +to the same location you did initially in order for the TorChat +launcher to continue to work. + +### Python ### + +If you used built-in Python, Python will update through Software +Update/App Store. The launcher script will continue to function. + +If you installed Python from MacPorts, `sudo port upgrade outdated` +will automatically update you, and your TorChat launcher will continue +to work. + +If you downloaded a pre-built binary of Python, just download and run +the appropriate newer installer. As long as it installs to the same +location as it did the first time, your TorChat launcher will continue +to work. + +### wxPython ### + +If you downloaded a pre-built binary of wxPython, just download and +run the appropriate newer installer. As long as it installs to the +same location as it did the first time, your TorChat launcher will +continue to work. + +If you installed wxPython from MacPorts, `sudo port upgrade outdated` +will automatically update you, and your TorChat launcher will continue +to work. + +If you built wxPython from source, you will need to build the new +version and install it to the same location you did initially. If you +do so, your TorChat launcher will continue to work. + +### TorChat ### + +When a new TorChat is released, a new torchat-source entry will appear +on [the Downloads +page](https://github.com/prof7bit/TorChat/downloads). Before +downloading, remove the old torchat-source files from your Downloads +folder, then follow instructions as if you were installing TorChat +above. You do not need to recreate the launcher; it will continue to +work. diff --git a/torchat/doc/howto_second_instance.html b/torchat/doc/howto_second_instance.html index c26ad633..e9db4a44 100644 --- a/torchat/doc/howto_second_instance.html +++ b/torchat/doc/howto_second_instance.html @@ -9,7 +9,7 @@

- How to run more than on instance of TorChat + How to run more than one instance of TorChat

This howto will not work with versions below 0.9.9.260 @@ -17,12 +17,12 @@

First I will explain how torchat.ini and portable mode are working and where all relevant data files are located. Then I will explain some - things about adresses and port numbers of the client and the Tor proxy. + things about addresses and port numbers of the client and the Tor proxy. You should fully understand this before you go on to the second part where we actually move files around and change some of the settings.

- Most of the this document is primarily targeted towards users of Microsoft + Most of this document is primarily targeted towards users of Microsoft Windows, because Windows is by far the most complicated operating system in existence. Users of Unix/Linux based operating systems can easily adopt all the information here for their platforms without problems. @@ -44,9 +44,9 @@

portable mode or permanent installation

-

+

Portable Mode means that all that is needed is contained in one folder - which you can carry around on an usb drive and run it wherever you + which you can carry around on a usb drive and run it wherever you happen to be. Therefore TorChat (for windows) comes bundled with its own tor.exe which it will try to start and all settings and data files remain inside this folder. Nothing will be copied or installed outside this folder @@ -58,39 +58,39 @@

with a special TorChat configuration (torrc.txt). The only difference on *ix is that you will have to install Tor yourself in order to be able to use TorChat. -

-

+

+

Then there is the Permanent Installation. TorChat can be installed - to a read-only folder like c:\programs\ or /usr/* and all of it's data and + to a read-only folder like c:\programs\ or /usr/* and all of its data and configuration will be in %APPDATA%\torchat\ or ~/.torchat/ In This mode TorChat will create a copy of the "Tor" folder in the data directory and use that instead just as it would use it in portable mode. On *ix systems this Tor folder will contain the torrc.txt with the port settings for this profile and the tor.sh to start an already installed - tor service with this settings. On Windows systems it will contain it's + tor service with these settings. On Windows systems it will contain its own tor.exe instead of the shell script. -

-

- Finally there is another variant of operation, the Client Mode +

+

+ Finally there is another variant of operation, the Client Mode. This mode is only useful in rare special cases if you want to run TorChat over some already running (and correctly configured) Tor proxy in your network or on your machine. This mode is for experts only. -

-

+

+

The next few sections will explain how the mode is selected and how this is related to the configuration files. -

+

portable.txt

- There is a file called portable.txt. It's contents are completely - irrelevant, in fact it could be empty, only it's existance is an - indicator wether TorChat should run in portable mode or not. If you delete - this file, TorChat will store all it's data like the buddy-list and the - configuration file in the user's home directory - If the file portable.txt exists TorChat will look for all - it's configuration and data in the same folder where torchat.exe + There is a file called portable.txt. Its contents are completely + irrelevant, in fact it could be empty, only its existence is an + indicator whether TorChat should run in portable mode or not. If you delete + this file, TorChat will store all its data like the buddy-list and the + configuration file in the user's home directory. + If the file portable.txt exists, TorChat will look for all + its configuration and data in the same folder where torchat.exe (or .py on *ix systems) is located.

@@ -99,9 +99,9 @@

torchat.ini will be automatically created at the first start of TorChat or whenever it has been deleted or moved and TorChat can not find it. - Depending on wether the portable.txt is found or not TorChat + Depending on whether the portable.txt is found or not, TorChat will look for torchat.ini in the current directory or in the - user's home directory. torchat.ini contains two sections + user's home directory. torchat.ini contains two sections: [tor] and [tor_portable]. If TorChat was able to successfully start the bundled tor.exe (or the tor.sh script on *ix) the section [tor_portable] is used, else it will use the settings in [tor] @@ -112,17 +112,17 @@

The folder Tor

- If we are in portable mode (portable.txt) TorChat will use the the Tor + If we are in portable mode (if portable.txt was found) TorChat will use the Tor folder that is in the TorChat directory and try to start Tor\tor.exe (or Tor/tor.sh) with the Tor configuration in Tor\torrc.txt.

- If we are not in portable mode TorChat will look for this Tor folder in - the user's data directory (~/.torchat or %APPDATA%\torchat) and start it's + If we are not in portable mode, TorChat will look for this Tor folder in + the user's data directory (~/.torchat or %APPDATA%\torchat) and start its tor service from within there.

- If you delete the tor.exe (or tor.sh on *ix) you can force TorChat into + If you delete the tor.exe (or tor.sh on *ix), you can force TorChat into using an already installed Tor service on your network. This is the Client Mode. It is not recommended for normal users. TorChat will use the settings in [tor] instead of those in [tor_portable] and you @@ -142,7 +142,7 @@

else: -> Permanent Installation -> use home folder for all data - + if can start tor.exe (or tor.sh): -> normal mode of operation -> use settings in torchat.ini/[tor_portable] and torrc.txt @@ -150,7 +150,6 @@

-> Client Mode -> use settings in [tor] -> all must be configured manually! -

or if you are more attracted to tables we can summarize it in a tabular way: @@ -187,7 +186,7 @@

missing missing Client mode (permanent installation)
- like Permanent Installaton
+ like Permanent Installation
but settings in [tor] are used.
Only experienced users should use this, all has to be configured manually @@ -201,18 +200,18 @@

In this Mode normally you don't have to configure anything. The Tor binary which is bundled with TorChat will be started with /Tor/torrc.txt - as it's configuration file. Out of the box it is configured to listen on + as its configuration file. Out of the box it is configured to listen on port 11109 (socks) and port 11119 (control) and to forward the hidden - service port 11009 to localhost:11009. Note that this are the same - port numbers as configured in torchat.ini section [tor_portable] + service port 11009 to localhost:11009. Note that these are the same + port numbers as configured in torchat.ini section [tor_portable].

- The hidden service directory is hidden_service + The hidden service directory is hidden_service inside the Tor folder. You may not change this.

If you plan to run a second portable instance on the same computer - you will have to change all this port numbers and also the corresponding + you will have to change all the port numbers and also the corresponding settings in torchat.ini section [tor_portable] and [client] in the second copy of the whole TorChat folder.

@@ -227,15 +226,15 @@

Additionally you can use different profiles, if you start torchat with the name of a profile at the commandline. If you start TorChat with the - commandline
+ commandline:

    torchat HansFranz
   

it will use the folder ~/.torchat_HansFranz/ or %APPDATA%\torchat_HansFranz\ - and have a copy of it's Tor folder in this directory, so you can change the - port numbers only for this profile and will be able to run as much different + and have a copy of its Tor folder in this directory, so you can change the + port numbers only for this profile and will be able to run as many different profiles on the same machine as you want as long as you avoid conflicting port numbers.

@@ -256,13 +255,13 @@

Client Mode (not recommended)

HiddenServicePort 11009 localhost:11009

- Now restart your Tor service, make sure it runs without errors. While Tor is + Now restart your Tor service, make sure it runs without errors. When Tor is now running again in the background as normal, have a look into our hidden service folder we just created. There should be two files (which have been created by Tor). One is named private_key and one is named hostname. Inside this file (open it with notepad) you will find your .onion address. It will be something like 16crypticletters.onion. Later on in this - document i will refer to this 16 cryptic letters as your .onion address. + document I will refer to this 16 cryptic letters as your .onion address. Put this .onion address (without the .onion at the end) into your torchat.ini under own_hostname or it will not work. Otherwise TorChat has no way of finding out what his own hidden hostname is. @@ -276,7 +275,7 @@

The configuration of TorChat

- Torchat ist configured with torchat.ini. Where this file is located depends + Torchat is configured with torchat.ini. Where this file is located depends on the mode (portable or permanent, see above). Two sections in this configuration file are of interest here: [tor_portable] and [client].

@@ -292,17 +291,17 @@

If you are running in Client Mode (delete tor.exe or tor.sh), which is - not recommended for unexperienced users, then the settings in [tor] are - used instead of those in [tor_portable]. In this mode you are rsponsable + not recommended for inexperienced users, then the settings in [tor] are + used instead of those in [tor_portable]. In this mode you are responsible for configuring a hidden service manually and finding out the correct - setting for own_hostname yourself, which otherwise would be done + setting for own_hostname yourself, which otherwise would be done automatically.

Part 2 - Some common scenarios

Now you have learned enough to actually make changes to the configuration. - Following are a few common scenarios and how to configure them + Following are a few common scenarios and how to configure them.

A second instance in portable mode @@ -318,7 +317,7 @@

Scenario: You already have TorChat running in portable mode and you - want another instance of it running on the same computer with it's own + want another instance of it running on the same computer with its own settings and buddy list.

@@ -328,7 +327,7 @@

Step 2: Make this copy virgin again. Delete the file buddy-list.txt, - go to the folder Tor, delete the two folders hidden_service and tor_data + go to the folder Tor, delete the two folders hidden_service and tor_data.

Step 3: Configure the second Tor instance: We know that our ports @@ -370,8 +369,8 @@

listen_port = 22009

- The setting own_hostname can be left alone. it will be updated - automatically. In Full Portble Mode TorChat will look into the + The setting own_hostname can be left alone, it will be updated + automatically. In Full Portable Mode, TorChat will look into the hostname file, extract the hostname from it and automatically fill in the correct value.

@@ -379,11 +378,11 @@

Step 5: Try it out! It is time to start your second copy of TorChat. It should start with an empty buddy list with only the newly generated unique hostname as "myself" on it. Remember that it can take some time - until the myself-icon will become green. + until the myself-icon becomes green.

If it doesn't become green after more than 15 minutes then there is - something wrong. If all your contacts get stuck in the state with blue + something wrong. If all your contacts get stuck in the state with a blue earth symbol and never turn green, then this is a sign that outgoing connections work, but incoming connections don't work. In this case make sure that HiddenServicePort in torrc.txt and listen_port in torchat.ini @@ -398,16 +397,16 @@

If you have installed the .deb package on debian, ubuntu or similar - operating systems, and started TorChat for the first time then there - sould be a folder ~/.torchat/ in your home directory. Inside this folder - there is your torchat.ini and another folder 'Tor' with torrc.txt + operating systems, and started TorChat for the first time, then there + should be a folder ~/.torchat/ in your home directory. Inside this folder + there is your torchat.ini and another folder 'Tor' with torrc.txt.

Now quit this instance of TorChat. Never quit TorChat by hitting Ctrl-C in the terminal, always use "quit" from - the menu, because TorChat must be able to properly stop it's child + the menu, because TorChat must be able to properly stop its child process (tor.sh with tor) or you will have a tor process hanging around - that will still provide it's hidden service and is bound to the ports + that will still provide its hidden service and is bound to the ports it was configured to use.

@@ -435,13 +434,14 @@

Using your already installed Tor service

- yet to be written... + yet to be written...

More than one instance using the same Tor service

- yet to be written... + yet to be written...

+ diff --git a/torchat/src/Tor/torrc.txt b/torchat/src/Tor/torrc.txt index 414b711b..d247fa47 100644 --- a/torchat/src/Tor/torrc.txt +++ b/torchat/src/Tor/torrc.txt @@ -29,7 +29,7 @@ SocksPort 11109 HiddenServiceDir hidden_service HiddenServicePort 11009 127.0.0.1:11009 -## where should tor store it's cache files +## where should tor store its cache files DataDirectory tor_data ## some tuning diff --git a/torchat/src/config.py b/torchat/src/config.py index be158105..bc90845c 100644 --- a/torchat/src/config.py +++ b/torchat/src/config.py @@ -2,7 +2,7 @@ ############################################################################## # # -# Copyright (c) 2007-2010 Bernd Kreuss # +# Copyright (c) 2007-2013 Bernd Kreuss # # # # This program is licensed under the GNU General Public License V3, # # the full source code is included in the binary distribution. # @@ -74,27 +74,13 @@ def isWindows(): except: CONSOLE_ENC = None -def toUnicode(unknownstr): - # some things like sys.argv[] and also functions from os.path - # return bytestrings. Since I don't know if this might change - # eventually in some future Python version I need something to - # decode them only if needed. (I try to decode everything as - # soon as possible and only work with unicode everywhere) - # Note: it seems none of these strings I have come across so far - # was ever encoded in the console encoding, they all seem to use - # the locale encoding. - if isinstance(unknownstr, str): - return unknownstr.decode(LOCALE_ENC) - else: - return unknownstr - -COPYRIGHT = u"Copyright (c) 2007-2011 Bernd Kreuß " +COPYRIGHT = u"Copyright (c) 2007-2013 Bernd Kreuß " DEAD_CONNECTION_TIMEOUT = 240 KEEPALIVE_INTERVAL = 120 MAX_UNANSWERED_PINGS = 4 -SCRIPT_DIR = os.path.abspath(os.path.dirname(toUnicode(sys.argv[0]))) +SCRIPT_DIR = os.path.abspath(os.path.dirname(unicode(sys.argv[0]))) ICON_DIR = os.path.join(SCRIPT_DIR, "icons") log_writer = None cached_data_dir = None @@ -143,7 +129,7 @@ def getHomeDir(): ctypes.windll.shell32.SHGetSpecialFolderPathW(None, buf, CSIDL_PERSONAL, 0) return buf.value else: - return toUnicode(os.path.expanduser("~")) + return unicode(os.path.expanduser("~")) def getDataDir(): global cached_data_dir @@ -161,12 +147,12 @@ def getDataDir(): appdata = buf.value data_dir = os.path.join(appdata, "torchat") else: - home = toUnicode(os.path.expanduser("~")) + home = unicode(os.path.expanduser("~")) data_dir = os.path.join(home, ".torchat") #test for optional profile name in command line try: - data_dir += "_" + toUnicode(sys.argv[1]) + data_dir += "_" + unicode(sys.argv[1]) except: pass @@ -200,7 +186,7 @@ def getDataDir(): def getProfileLongName(): try: - return "%s - %s" % (toUnicode(sys.argv[1]), get("client", "own_hostname")) + return "%s - %s" % (unicode(sys.argv[1]), get("client", "own_hostname")) except: return get("client", "own_hostname") @@ -479,7 +465,7 @@ def main(): if isPortable(): print "(0) running in portable mode, all data is kept inside the bin folder." if (len(sys.argv) > 1): - print "(0) ignoring requested profile '%s' because profiles do not exist in portable mode" % toUnicode(sys.argv[1]) + print "(0) ignoring requested profile '%s' because profiles do not exist in portable mode" % unicode(sys.argv[1]) print "(0) script directory is %s" % SCRIPT_DIR print "(0) data directory is %s" % getDataDir() diff --git a/torchat/src/portable.txt b/torchat/src/portable.txt index 3a22f29e..5f4bc199 100644 --- a/torchat/src/portable.txt +++ b/torchat/src/portable.txt @@ -2,18 +2,18 @@ This file (portable.txt) is used to indicate that TorChat is running in portable mode. If this file is found in this folder, all config and data will be stored in the program folder itself, rather -than in the users home directory. +than in the user's home directory. If you delete this file, then TorChat will create a folder ~/.torchat (or %AppData%\torchat on w32) -on the computer's harddisk and store it's +on the computer's harddisk and store its configuration and data there, so if you plan to run the program from a removable media, leave this file where it is. -Distributors and packagers remove this file if +Distributors and packagers can remove this file if a fixed installation of TorChat is desired. The contents of this file are irrelevant. It could also be completely empty. It is only checked if -there is a file "portable.txt" or not. \ No newline at end of file +there is a file "portable.txt" or not. diff --git a/torchat/src/tc_client.py b/torchat/src/tc_client.py index bbcf63ea..a37f55f6 100644 --- a/torchat/src/tc_client.py +++ b/torchat/src/tc_client.py @@ -80,7 +80,7 @@ def encodeLF(blob): # # Please do not rant in the source code comments of your # own protocol implementations about how "suboptimal" my - # decision was, actally I spent quite some time thinking + # decision was, actually I spent quite some time thinking # about it in the early design phase and this solution is # pragmatic, easy to implement and rock solid. # @@ -88,7 +88,7 @@ def encodeLF(blob): # bandwidth wasting base64, there is NO NEED for it, # TorChat is NOT a text based protocol in the common # sense, we are transmitting binary data over 8-bit-clean - # sockets. We don't have to fit them into RFC confoming + # sockets. We don't have to fit them into RFC-conforming # message bodies of SMTP or NNTP messages, print them # line by line on a terminal or a printer or anything # else that would interpret control characters. The @@ -107,7 +107,7 @@ def decodeLF(line): """takes the line as it comes from the socket and decodes it to the original binary data contained in a string of bytes""" return line.replace("\\n", "\n").replace("\\/", "\\") - + def createTemporaryFile(file_name): if config.getint("files", "temp_files_in_data_dir"): @@ -167,14 +167,14 @@ def run(self): def wipeFile(file_name): """Wipe a file by first overwriting it with random data, synching it to disk and finally unlinking it. For this - purpose it will start a separat thread to do this in the + purpose it will start a separate thread to do this in the background and return immediately.""" WipeFileThread(file_name) #--- ### Client API class Buddy(object): - """Represets a buddy. Every buddy on the buddy list will have sich + """Represents a buddy. Every buddy on the buddy list will have an instance created directly after program start and also every new connection from unknown addresses will result in the instantiation of a new buddy object when a valid ping message has been processed. @@ -295,7 +295,7 @@ def onProfileText(self, text): def onAvatarDataAlpha(self, data): print "(2) %s.onAvatarDataAplha()" % self.address # just store it, no gui callback because this is always sent first. - # The next message will be the acual image data which will finally notify the GUI + # The next message will be the actual image data which will finally notify the GUI self.profile_avatar_data_alpha = data def onAvatarData(self, data): @@ -306,7 +306,7 @@ def onAvatarData(self, data): def onChatMessage(self, message): self.bl.gui(CB_TYPE_CHAT, (self, message)) - + def sendChatMessage(self, text): #text must be unicode, will be encoded to UTF-8 if self.isFullyConnected(): @@ -337,7 +337,7 @@ def getOfflineMessages(self): def sendOfflineMessages(self): #this will be called in the incoming status message - #FIXME: call this from onStatus() instead, this would be the ntural place for it + #FIXME: call this from onStatus() instead, this would be the natural place for it text = self.getOfflineMessages() if text: if self.isFullyConnected(): @@ -360,6 +360,7 @@ def getDisplayNameOrAddress(self): return self.name def getAddressAndDisplayName(self): + # TODO: This is just the same as getDisplayName(), right? if self.name == "": return self.address else: @@ -391,13 +392,12 @@ def startTimer(self): #otherwise we would create a unique pattern of activity #over time that could be identified at the other side if self.status == STATUS_HANDSHAKE: - # ping more agressively during handshake + # ping more aggressively during handshake # to trigger more connect back attempts there t = config.KEEPALIVE_INTERVAL / 4 else: # when fully connected we can slow down to normal t = config.KEEPALIVE_INTERVAL - if self.timer: self.timer.cancel() @@ -822,7 +822,7 @@ def sendBlocks(self, first): while not self.buddy.isFullyConnected() and not self.restart_flag: time.sleep(0.1) self.testTimeout() - + # the message is sent over conn_in msg = ProtocolMsg_filedata(self.buddy.conn_in, (self.id, start, hash, data)) msg.send() @@ -834,12 +834,12 @@ def sendBlocks(self, first): if self.restart_flag: #the outer loop in run() will start us again - print "(2) FileSender restart_flag, breaking innner loop" + print "(2) FileSender restart_flag, breaking inner loop" break if not self.running: #the outer loop in run() will also end - print "(2) FileSender not running, breaking innner loop" + print "(2) FileSender not running, breaking inner loop" break print "(2) FileSender inner loop ended, last sent block: #%i, last block in file #%i" % (i, blocks-1) @@ -920,7 +920,7 @@ def receivedOK(self, start): self.completed = True def restart(self, start): - #trigger the reatart flag + #trigger the restart flag self.timeout_count = 0 self.restart_at = start self.restart_flag = True @@ -943,7 +943,7 @@ def close(self): class FileReceiver(object): - # ths will be instantiated automatically on an incoming file transfer. + # this will be instantiated automatically on an incoming file transfer. # it will then notify the GUI which will open a window and give us a callback to interact def __init__(self, buddy, id, block_size, file_size, file_name): self.buddy = buddy @@ -1061,7 +1061,7 @@ def close(self): # therefore this FileReceiver object cannot work without # a GUI attached to it (or some other piece of code) that # properly provides and reacts to the callback function - # and closes this obect after it is done + # and closes this object after it is done # (user clicked save or whatever this GUI or GUI-replacement does) if self.closed: @@ -1119,7 +1119,7 @@ class ProtocolMsg(object): def __init__(self, *args): """ this is actually a few overloaded constructors, - depending on the types of argumments + depending on the types of arguments when receiving a message we instantiate it like this: __init__(self, bl, connection, command, encoded) @@ -1154,8 +1154,8 @@ def __init__(self, *args): # the incoming message is now properly initialized and somebody # could now call its execute() method to trigger its action return - - + + # # outgoing # @@ -1200,11 +1200,11 @@ def execute(self): self.connection.close() def getLine(self): - """return the entire message readily encoded as a string of charactrs + """return the entire message readily encoded as a string of characters that we can transmit over the socket, terminated by a 0x0a character""" # This is important: # The data that is transmitted over the socket (the entire contents - # of one protocol message will be put into one string of bytes that + # of one protocol message) will be put into one string of bytes that # is terminated by exactly one newline character 0x0a at the end. # # This string of bytes is what I refer to as the "line" @@ -1244,7 +1244,7 @@ def execute(self): class ProtocolMsg_ping(ProtocolMsg): """a ping message consists of sender address and a random string (cookie). - It must be answered with a pong message containing the same cookie to so that + It must be answered with a pong message containing the same cookie so that the other side can undoubtedly identify the connection""" def parse(self): self.address, self.answer = splitLine(self.blob) @@ -1405,7 +1405,7 @@ def execute(self): #MITM protection: #this pong is an answer to a ping we have sent to a different address. #we will simply ignore this pong to make any mitm attacks that - #simply try to forward original pings to other clients impossilbe + #simply try to forward original pings to other clients impossible print "(2) ignoring pong from %s which should have come from %s" % (self.connection.last_ping_address, buddy.address) return @@ -1447,12 +1447,12 @@ def execute(self): class ProtocolMsg_status(ProtocolMsg): """transmit the status, this MUST be sent every 120 seconds - or the client may trigger a timeout and close the conection. + or the client may trigger a timeout and close the connection. When receiving this message the client will update the status icon of the buddy, it will be transmitted after the pong upon connection, immediately on every status change or at least once every 120 seconds. Allowed values for the data are - "avalable", "away", "xa", other values are not defined yet""" + "available", "away", "xa", other values are not defined yet""" def parse(self): self.status = self.blob @@ -1479,7 +1479,7 @@ def execute(self): class ProtocolMsg_profile_name(ProtocolMsg): - """transmit the name that is set in the pofile (this message is optional)""" + """transmit the name that is set in the profile (this message is optional)""" def parse(self): self.name = self.blob.decode("UTF-8") @@ -1490,7 +1490,7 @@ def execute(self): class ProtocolMsg_profile_text(ProtocolMsg): - """transmit the text that is set in the pofile (this message is optional)""" + """transmit the text that is set in the profile (this message is optional)""" def parse(self): self.text = self.blob.decode("UTF-8") @@ -1517,14 +1517,14 @@ def execute(self): if self.buddy: print "(2) received avatar alpha channel from %s (%i bytes)" % (self.buddy.address, len(self.bitmap)) if self.bitmap: - # the buddy obect stores the raw binary data + # the buddy object stores the raw binary data self.buddy.onAvatarDataAlpha(self.bitmap) else: print("(1) %s sent invalid avatar alpha data (wrong size)" % self.buddy.address) self.buddy.onAvatarDataAlpha("") class ProtocolMsg_profile_avatar(ProtocolMsg): - """the uncompesseed 64*64*24bit image. Avatar messages can + """the uncompressed 64*64*24bit image. Avatar messages can be completely omitted but IF they are sent then the correct order is first the alpha and then this one""" def parse(self): @@ -1537,7 +1537,7 @@ def execute(self): if self.buddy: print "(2) received avatar from %s (%i bytes)" % (self.buddy.address, len(self.bitmap)) if self.bitmap: - # the buddy obect stores the raw binary data + # the buddy object stores the raw binary data self.buddy.onAvatarData(self.bitmap) else: print("(1) %s sent invalid avatar image data (wrong size)" % self.buddy.address) @@ -1618,7 +1618,7 @@ def parse(self): self.file_size = int(file_size) self.block_size = int(block_size) - # the filename is tansmitted in UTF-8 encoding + # the filename is transmitted in UTF-8 encoding # so we decode the name to unicode (widestring) name = self.file_name.decode("utf-8") # remove all occurences 0x0000 @@ -1642,7 +1642,7 @@ def execute(self): return #we create a file receiver instance which can deal with the - #file data we expect to receive now. This obect will then + #file data we expect to receive now. This object will then #also notify the GUI and interact with it FileReceiver(self.buddy, self.id, @@ -1652,11 +1652,11 @@ def execute(self): class ProtocolMsg_filedata(ProtocolMsg): - """After a filename message has initiated the transfer several - filedata messagess transport the actual data in blocks of fixed + """After a filename message has initiated the transfer, several + filedata messages transport the actual data in blocks of fixed size. start is the byte offset of the block in the file and hash is an md5 hash of the block used as a checksum. Each message must - be answered with filedata_ok after sucessfully verifying the hash. + be answered with filedata_ok after successfully verifying the hash. The sender should send only a limited number of blocks ahead of incoming ok messages (for example send the 5th block only after the 1st is confirmed, the 6th only after the 2nd confirmed, etc., @@ -1715,10 +1715,10 @@ def execute(self): class ProtocolMsg_filedata_error(ProtocolMsg): """This is sent instead of filedata_ok when the hash was wrong or the block start - was later than what we would have expected (entire blocks have been skipped/lost + was later than what we expected (entire blocks have been skipped/lost due to temporary disconnect). A file sender must react to this message by restarting the file transmission at the offset given in start. A file receiver will - send this message whenever it wants the the transfer restart at a certain position.""" + send this message whenever it wants the transfer to restart at a certain position.""" def parse(self): self.id, start = splitLine(self.blob) self.start = int(start) # block start position in bytes @@ -1839,7 +1839,7 @@ def __init__(self, socket, buddy_list): self.buddy = None self.bl = buddy_list self.socket = socket - self.last_ping_address = "" #used to detect mass pings with fake adresses + self.last_ping_address = "" #used to detect mass pings with fake addresses self.last_ping_cookie = "" #used to detect pings with fake cookies self.last_active = time.time() self.started = True @@ -2102,7 +2102,7 @@ def startPortableTor(): print "(1) no own Tor instance. Settings in [tor] will be used" except: - print "(1) an error occured while starting tor, see traceback:" + print "(1) an error occurred while starting tor, see traceback:" tb(1) print "(1) changing working directory back to %s" % old_dir @@ -2127,3 +2127,4 @@ def onPortableTorTimer(): startPortableTor() else: startPortableTorTimer() +