Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add post by Jeremy "Porting Namecoin in Tor Browser to macOS" #579

Open
wants to merge 2 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions _posts/2020-09-21-porting-namecoin-in-tor-browser-to-macos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
layout: post
title: "Porting Namecoin in Tor Browser to macOS"
author: Jeremy Rand
tags: [News]
---

Hot on the heels of [porting Namecoin in Tor Browser to Windows]({{ "/2020/08/28/porting-namecoin-in-tor-browser-to-windows.html" | relative_url }}), it was time to do the final remaining desktop OS, macOS. This one was always going to present a challenge in the QA testing department, because I don't own any macOS devices. On the other hand, I fully expected that the amount of code written for macOS support was going to be pretty minimal; in fact I expected that other than tweaking a few constants, macOS support was likely to be a subset of the code needed for Windows support. But of course, our friend Murphy wasn't going to let that assumption stand.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fully expected that the amount of code written for macOS support was going to be pretty minimal

I fully expected the amount of code written for macOS support to be pretty minimal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggestion erases the future-ish tense for "written", so I'd prefer not to make this change.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. In that case, how about "I fully expected that the amount of code written for macOS support would be going to be pretty minimal"?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact I expected

in fact, I expected

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objection.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But of course,

But, of course,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objection.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our friend Murphy wasn't going to let that assumption stand.

our friend Mr. Murphy wasn't going to let that assumption stand.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike titles, so I'm not going to add Mr. here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think it should be indicated that it's a family name and not a given name, but since I don't see any way to do that without honorifics, I won't insist on it.


On the bright side, two of our community members who do have macOS devices volunteered to test my binaries and supply me with debug logs when things failed. So at least that wasn't going to prevent a successful port.

## Initial Attempt

As a first try, I added the Electrum-NMC, ncprop279, and StemNS dependencies (with their config files) to the `tor-browser` rbm project, and added the missing lines in Tor Launcher for determining the paths of Electrum-NMC and StemNS on macOS. Then I fliped the `var/namecoin` switch for macOS in `tor-browser-build`, and started up a build job. In order to build without errors, I then needed to make some slight edits to the build scripts of some of the Go projects that `ncprop279` depends on, mostly related to cgo edge cases.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(with their config files)

, and their config files,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't really fit my style; I prefer a parenthetical here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fliped

flipped

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and started up a build job

and started a build job

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't really fit my style.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

job. In

job. The build errored. In

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figure this is implied by the next sentence.

Copy link

@yanmaani yanmaani Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but I had to read it a few times over to understand it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to

To

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't really fit my style.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of some of the Go projects that ncprop279

of the Go projects that ncprop279
of some of the Go projects which ncprop279
(some ... that is doubly restrictive)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I'm not even sure what grammar rule is being cited here, but I suspect that whatever grammar rule is involved is not something I'm in the habit of following. So, doesn't fit my style.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like I misread that sentence.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depends on

(up)on which ... depends

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware that English theoretically has a rule about ending sentences with prepositions, but I find that this rule makes things less pleasant to read, and so I deliberately do not follow it. (I'm a language anarchist, I have no issue with violating theoretical language rules if doing so makes the writing more effective.)


Alas, the resulting binaries consistently failed to detect Electrum-NMC and ncprop279.

## What is this external user data craziness?

It turns out that Tor Browser for macOS does something very different from Tor Browser for GNU/Linux and Windows. On macOS, the user data directory is stored separately from the application executable code. To make matters worse, on macOS there is no way to supply "default" contents for the user data directory. In fact, in order to set the default bookmarks for Firefox, Tor Browser on macOS does some kind of witchcraft involving stuffing the bookmarks file inside one of the Firefox application archives, such that when Firefox eventually creates a fresh profile, the bookmarks end up in the desired place. For non-Firefox data, there simply is no mechanism at all. Even the file `torrc`, which exists in the source code, never actually gets installed on macOS (which I suppose is tolerated because it's an empty file, so who cares if it gets installed?).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supply "default" contents

supply default contents

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't really fit my style.

Copy link

@yanmaani yanmaani Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are they not real default contents in some way? Why the quotes?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order to

to

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't fit my style.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(which I suppose is tolerated because it's an empty file, so who cares if it gets installed?).
I suppose this is tolerated because it's an empty file; who cares if it gets installed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't fit my style.


Alas, the Namecoin support in Tor Browser relies on supplying default config files for both Electrum-NMC and ncprop279. Fixing this was going to take some refactoring.

## Electrum-NMC Support

I considered a few options here. Initially the thought occurred to me of patching Electrum-NMC to support a read-only config file in a separate directory from its writeable data directory. Alas, this seemed rather invasive, and I didn't want to write a complex patch without good reason. I also considered generating the config file on-demand as part of Tor Launcher, but this was also not going to be very clean. Instead, I realized that we could just pass the config options we cared about as command-line flags, not supply a default config file at all, and be done with it.

Oh wait. Murphy says no. Turns out that the RPC port settings in Electrum can't be set on the command-line, only in the config file. Upon consulting with SomberNight from upstream Electrum, he pointed me to a spot in the relevant Python source, where I could probably do a 3-line patch that would do what I want, and would probably be upstreamable without controversy. This ended up working very well. We were thus able to launch Electrum-NMC.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Murphy

Mr. Murphy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, I dislike titles.


## ncprop279 Support

This one was easier. ncprop279 doesn't need to write to any config directory, and it will happily look for a config file adjacent to its executable file if one is there. So I just stuck `ncprop279.conf` in the same directory as the executable, and we were done there.

## StemNS Support

A minor tweak was needed for StemNS, so that it would search for `ncprop279` relative to StemNS's script directory instead of relative to the `PATH`. Turns out that macOS doesn't standardize the `PATH` in the way that GNU/Linux and Windows do, so relying on the `PATH` wasn't usable on macOS. Not too bad.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it not too bad that you can't rely on the PATH on macOS?

Upon re-reading, I realize the "not too bad" applies to how much work it was, but this should probably be re-worded so it's obvious the second sentence is related to the first


I also took the opportunity to do some minor refactoring/cleanup of StemNS, mostly related to error handling and debug logging. Now the console output of StemNS is actually likely to be informative. (My beta testers very much appreciated this.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactoring/cleanup

refactoring and cleanup

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't fit my style.


## It works? It works!

At this point it seems to work perfectly. I still need to squash Git history and do some final checks on GNU/Linux and Windows to make sure the refactors didn't break anything, and then I'll hand it off to the Tor Browser devs.

![A screenshot of Namecoin in Tor Browser on macOS.]({{ "/images/screenshots/tor/tor-browser-macos-2020-09-20.png" | relative_url }})

This work was funded by Cyphrs and Cyberia Computer Club.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.