Custom syncthing server daemon

Hi all,

I’m getting my hands dirty on the source code (copy of cmd/syncthing -> The current syncthing client/server is not sufficient for my use-case. As I want a dropbox-like experience and have a NAS which acts as a “central-storage” place. I would like to allow only as list of devices which can auto-share with their files with the NAS. Currently the config is fairly deep woven into the lib. I’m a bit lost how lib/model works as you can AddFolder, StartFolder but this will not start syncing. I already found out the event system which emits a rejected folder event and can act on this to add it automaticly.

I’m not sure what direction I should take as probably other people would like this kind of setup (as alternative for dropbox). With the server-only daemon I could also expose a file-listing and file-link sharing which is currently not possible.

If there is something not clear in my post, I would like to describe further in detail.

Kind regards, Jerry

I think you need to do that, because it’s not clear to me what you’re trying to do. If you’re talking about automatically adding folders based on them being shared from a device, look into what happens in ClusterConfig() (that’s where you see what another device is sharing with you), and add them to the config as if they were added from the GUI.

What the server will do:

  • Accept only a selected list of devices (from config)
  • Auto-add rejected/unknown folders from devices (ClusterConfig)
  • Auto-share in readwrite mode folders which where auto-added from devices
  • Completely remove the client centric web-GUI
  • Completely remove local/global discovery announce

I already had a look at the ClusterConfig() where the rejectedfolder event is fired from. I hooked upon this event and added the folder to the config and started syncing.

I hacked something together to make it sort-of work but this is way dirty:

I had to expose the model.startFolder because I was clueless how it is possible to run the syncing.

Accepting only selected devices is of course the default, the discovery stuff can all be disabled by config, and the GUI you can remove I guess but it’s really just bundled HTML/JS files so no big deal. :slight_smile:

The automatic adding of new shares is the one that requires some development, and you could indeed do it based on the FolderRejected event. I’d create a specific event listener for that if you want to do it cleanly - basically just copy and paste verboseservice.go into folderadderservice.go or whatever, remove the handling of all other events, change the subscribe call to be only for FolderRejected, and wire it up in main in the same manner as the verbose service.

But you should not be reaching into the model hairball from there. Instead, get a reference to the global-ish cfg object, modify it to create the folder and add it to devices as appropriate, and call Save() on it. The folder gets added to the config, the config gets saved, the model reloads everything as necessary to start the folders - because it subscribes to config updates.

Hi Jakob (@calmh),

Thank you for your reply. When I digged deep in the model I was aware I should not modify the model at all.

I was aware of the Save() on config. But I was not sure if everything would reload and start the folders.

It would be more nice to have a separate service I recycled the verboseservice for hacking purposes.

1 Like

I have it sort-of working now, I still would like to (re)use the code of the model.ClusterConfig for introducers adding shared folders. It would be nice if we could create a function out if this code for reusability: