iOS Port of Syncthing

I’am working on a iOS Port of Syncthing, i am able now after some weeks to compile go source for iOS arm & arm64, now i can compile go source as a library like a go-output.a file with c header like _cgo_export.h and run go code on iOS Devices.

In the next weeks i will puplish the workaround how to do this for go source on iOS.

But now i need a little bit help to compile Syncthing

//THIS IS JUST A BASIC EXAMPLE WHAT I MUST DO For Compile:

CGO_ENABLED=1 GOARCH=arm64 GOARM=7 $GO tool cgo -objdir $GG_CGO_OBJ main.go
cp $GG_CGO_OBJ/_cgo_export.h /Users/XXXXXXX/go1.5/ios/src/github.com/syncthing/syncthing

#CGO_ENABLED=1 GOARCH=arm GOARM=7 $GO build -ldflags '-tmpdir ../go-obj -linkmode external'

Imports

/*
#cgo LDFLAGS: -framework UIKit -framework Foundation -framework CoreGraphics
extern void iosmain(int argc, char *argv[]);
*/
import "C"

func main() {
fmt.Printf("Hello from Saber from Go!\n")
C.iosmain(0, nil)
}


//export WebServer
func WebServer() {
fmt.Println("------------------WebServer--------------")
fmt.Printf("Now lets run the Webserver!\n")
fmt.Println("------------------WebServer--------------")
//Continue with some Code

I think the file which i must modify is /github.com/syncthing/syncthing/cmd/syncthing/main.go right?

4 Likes

OK, looks better now:

C Header _cgo_export.h is now generated with link to iosmain() xcode

Build for arm64 looks also fine, when i run it, it shows be “Bad CPU…”, is a good sign!

Next step:

-ldflags ‘-tmpdir …/go-obj -linkmode external’ this makes troubles because i can use it in the console, i must find the ldflags and adjust it in Syncthing.

-ldflags also done by the way.

Hello to Syncthing from Go!!! 2015-07-06 04:50:47.179 SyncthingWebView [804:177827] Hello to Syncthing from Object C!!! 2015-07-06 04:50:48.224 SyncthingWebView[804:177827] -[SyncthingWebViewViewController updateButtons] loading = YES 2015-07-06 04:50:48.301 SyncthingWebView[804:177827] -[SyncthingWebViewViewController updateButtons] loading = NO

Now its time to fix a lot of things for iOS… but i need sleep…

4 Likes

Neat.

i fixed now a lot of stuff puhhh… so compile is done… and no errors anymore…just some warnings about icons… nothing important right now.

when i start the iOS App, i get permission denied error, i think this happend because it try to generate the config.xml and the ssh key’s… right?

Where i can find this part to adjust this parts… on ios i must move all to the Documents folder dynamically, this is the only folder which Apple allows me to create or modify files inside the sandbox.

monitor.go trys to start a second process which is not allowed in iOS… i have some pain now… haha

The monitor process is optional though. Check the code path for STNORESTART=1.

-no-restart

You then become responsible for restarting Syncthing if it exits with an exit code which indicates it wants to be restarted.

-no-restart at this time is not possible… see monitor.go… because it fails on first start… forc/exec is not allowed, just threads on iOS…

            Infoln("Starting syncthing")
		err = cmd.Start()
		if err != nil {
            Infoln("1 Starting failed!!!!!!!!!!!")
            Fatalln(err)
		}
		// Let the next child process know that this is not the first time
		// it's starting up.
		os.Setenv("STRESTART", "yes")

The monitor process is never involved at all in the STNORESTART path. There is no fork.

Good to know let me try :slight_smile:

I would say this is now awesome!!!

Check this out:

Say hello to Syncthing from Go! 2015-07-06 17:40:52.552 IDZWebBrowser[1366:329658] Hello to Syncthing from Object C!!! ------------------WebServer-------------- Now lets run the Webserver! ------------------WebServer-------------- [start] 16:40:52 INFO: Generating RSA key and certificate for syncthing… 2015-07-06 17:40:54.868 IDZWebBrowser[1366:329658] -[IDZWebBrowserViewController updateButtons] loading = YES 2015-07-06 17:40:55.035 IDZWebBrowser[1366:329658] -[IDZWebBrowserViewController updateButtons] loading = NO [K2HOG] 16:41:13 INFO: syncthing unknown-dev (devel +300d9a2 Tue Jun 30 22:56:30 2015 +0000 darwin-arm64 default) unknown@unknown 1970-01-01 00:00:00 UTC [K2HOG] 16:41:13 INFO: My ID: K2HOGDV-2CD2P3N-LYNRWIW-T6XJAKR-HOZOCSY-ZFQT4NX-DH3IYBB-EH7IWAG [K2HOG] 16:41:13 INFO: No config file; starting with empty defaults [K2HOG] 16:41:13 INFO: Edit /private/var/mobile/Containers/Data/Application/8D2A1F26-4DD8-4027-BDC7-CC199DD249F8/Library/Application Support/Syncthing/config.xml to taste or use the GUI [K2HOG] 16:41:13 INFO: Starting deadlock detector with 20m0s timeout [K2HOG] 16:41:13 OK: Ready to synchronize default (read-write) [K2HOG] 16:41:13 INFO: Starting web GUI on http://127.0.0.1:8384/ [K2HOG] 16:41:13 INFO: Loading HTTPS certificate: open /private/var/mobile/Containers/Data/Application/8D2A1F26-4DD8-4027-BDC7-CC199DD249F8/Library/Application Support/Syncthing/https-cert.pem: no such file or directory [K2HOG] 16:41:13 INFO: Creating new HTTPS certificate [K2HOG] 16:41:13 INFO: Generating RSA key and certificate for iPhone-von-Saber-Gilani… [K2HOG] 16:41:13 WARNING: Stopping folder “default” - mkdir /private/var/mobile/Containers/Data/Application/8D2A1F26-4DD8-4027-BDC7-CC199DD249F8/Sync: operation not permitted [K2HOG] 16:41:13 INFO: Skipping folder default scan due to folder error: mkdir /private/var/mobile/Containers/Data/Application/8D2A1F26-4DD8-4027-BDC7-CC199DD249F8/Sync: operation not permitted [K2HOG] 16:41:18 INFO: Starting local discovery announcements [K2HOG] 16:41:18 INFO: Starting global discovery announcements [K2HOG] 16:41:18 INFO: API listening on 127.0.0.1:8384 [K2HOG] 16:41:18 INFO: Device K2HOGDV-2CD2P3N-LYNRWIW-T6XJAKR-HOZOCSY-ZFQT4NX-DH3IYBB-EH7IWAG is “iPhone-von-Saber-Gilani” at [dynamic] [K2HOG] 16:41:18 INFO: No automatic upgrades; unknown-dev is not a release version. [K2HOG] 16:41:31 INFO: New UPnP port mapping: external port 8712 to local port 22000.

Cool stuff, I guess you’ll have to jump hoops to get around the sandbox and in order to access the filesystem etc?

Did syncthing itself require any modifications? How is it being linked/invoked?

Are you using the iOS toolchain (GOOS=iOS) for Go?

2 Likes

Ohh yes this is now amazing, tonight i will work on the filesystem to get around the sandbox…

Yes i adjusted a some files in syncthing and i use a modified minix goios port the gernerate the .a file.

In the next weeks i will puplish the workaround in my blog and the xcode project.

2 Likes

I moved now all config and cert files to the iOS Documents Folder, now i am able to change the config add a new device or folder, because the document folder is write able.

But still i have a problem:

[KRYMQ] 13:58:23 INFO: Skipping folder default scan due to folder error: mkdir /private/var/mobile/Containers/Data/Application/CEE251AF-4A07-4890-945A-37EE25BFE81A:

I must change this to also to the documents folder like:

mkdir /private/var/mobile/Containers/Data/Application/CEE251AF-4A07-4890-945A-37EE25BFE81A/Documents

Any ideas where?

Update: This happend only with the default folder, with a new folder all is fine and sync works

probably the location of the default folder is not writeable because $HOME is not writeable on iOS (wherever it points to)?

<folder id="default" path="/private/var/mobile/Containers/Data/Application/6B48106D-212D-4634-9641-62ADB1AA55FE/Documents/Sync" ro="false" rescanIntervalS="60" ignorePerms="false" autoNormalize="true">

I change the default config.xml automatically when syncthing starts first time… more ideas?

I get all the time:

[KRYMQ] 15:21:06 INFO: Skipping folder default scan due to folder error: folder path missing

You can generate the config on first start via -generate, modify it with you local xml parser, and then restart syncthing.

I believe this is what syncthing-android does.

I know this is a possible way but do you like really this workaround with syncthing -generate ?

I think it more (nice) to modify the default config which Syncthing generates by first lunch after ssh cert generation.

And for me it looks not like a config.xml problem. I added now also a new folder, all is fine in the config.xml and sync works, but after restart i get “folder path missing” i think it happend somewhere else…