Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
Trac
Trac
  • Project overview
    • Project overview
    • Details
    • Activity
  • Issues 246
    • Issues 246
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Operations
    • Operations
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Activity
  • Create a new issue
  • Issue Boards
Collapse sidebar

GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

  • Legacy
  • TracTrac
  • Issues
  • #17051

Closed
Open
Created Sep 13, 2015 by Trac@tracbot

The binary reading on Windows platforms don't resolve the "0D0A"/"0A" problem.

When I run the first example from: https://stem.torproject.org/api/descriptor/microdescriptor.html

import os

from stem.control import Controller
from stem.descriptor import parse_file

with Controller.from_port(port = 9051) as controller:
  controller.authenticate()

  exit_digests = set()
  data_dir = controller.get_conf('DataDirectory')

  for desc in controller.get_microdescriptors():
    if desc.exit_policy.is_exiting_allowed():
      exit_digests.add(desc.digest)

  print 'Exit Relays:'

  for desc in parse_file(os.path.join(data_dir, 'cached-microdesc-consensus')):
    if desc.digest in exit_digests:
      print '  %s (%s)' % (desc.nickname, desc.fingerprint)

on Windows XP or Windows 10 the result was:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>example1.py
Exit Relays:

C:\>

After I replaced in "C:\Python27\Lib\site-packages\stem\descriptor_init_.py":

def _parse_file_for_path(descriptor_file, *args, **kwargs):
		with open(descriptor_file, 'rb') as desc_file:
			for desc in parse_file(desc_file, *args, **kwargs):
				yield desc

with

def _parse_file_for_path(descriptor_file, *args, **kwargs):
	if os.environ.get('OS','') != 'Windows_NT':
		with open(descriptor_file, 'rb') as desc_file:
			for desc in parse_file(desc_file, *args, **kwargs):
				yield desc
	if os.environ.get('OS','') == 'Windows_NT':
		with open(descriptor_file, 'r') as desc_file:
			for desc in parse_file(desc_file, *args, **kwargs):
				yield desc

the result is:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>example1.py
Exit Relays:
  CalyxInstitute14 (0011BD2485AD45D984EC4159C88FC066E5E3300E)
  ieditedtheconfig (0098C475875ABC4AA864738B1D1079F711C38287)
  default (00AE2BBFB5C0BBF25853B49E04CC76895044A795)
  ...

This bug was reported on #tor IRC channel by maiena and I fixed it with this patch.

The file "cached-microdesc-consensus" created by tor on Windows platforms end any line with CRLF (0D0A). As Python stated about "open(name[, mode[, buffering]])", "The most commonly-used values of mode are 'r' for reading, 'w' for writing (truncating the file if it already exists). If mode is omitted, it defaults to 'r'. The default is to use text mode, which may convert '\n' characters to a platform-specific representation on writing and back on reading."

That means that the binary reading on Windows platforms don't resolve the "0D0A"/"0A" problem.

Trac:
Username: TORques

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None