Skip to content
/ libipfs Public

Simple cgo wrapper for go-ipfs to be used in systems where separate daemons are not allowed or are otherwise suboptimal solution. The primary target is Sailfish OS.

License

Notifications You must be signed in to change notification settings

skvark/libipfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libipfs Build Status

Work in Progress! More information and features will be added when the project proceeds further.

Simple cgo wrapper for go-ipfs.

go-ipfs is usually run as a daemon with e.g. ipfs daemon. This is not possible in many systems (such as in Sailfish OS based mobile devices) which have more restricted environments and tighter rules for application deployment (no multiple executables allowed etc.).

The main purpose of this library is to be used as a dependency for actual applications in systems where separate daemons are not allowed. The CI (Travis) has been set up so that it produces RPM packages for Sailfish OS which is also the primary target of this library.

Build Process (Sailfish OS)

RPM packages are built on Travis with the help of SailfishOS SDK Docker image. Unfortunately it's not possible to build these packages on Mer Open Build Service since network connectivity is missing in the OBS environments. go-ipfs's as well as go's package management depends heavily on network availability.

The .spec file and packaging setup are somewhat unusual because go-ipfs and the wrapper library have to be cross-compiled with cgo for ARM platform with Sailfish OS SDK toolchains. Please see the .spec file and .travis.yml for the changes which have been made to be able to execute the build process successfully.

The go compiler is installed to the build environment during build.

Manual builds in other systems

While the primary target of this repository is Sailfish OS, the wrapper can be built for any system which is supported by go and go-ipfs.

  1. Install go if it's not installed.
  2. Fetch go-ipfs sources according to the guide in the go-ipfs README and run make deps in the source folder.
  3. Run CGO_ENABLED=1 go build -o libipfs.so -buildmode=c-shared src/go_ipfs_wrapper.go

You might want to set GOOS and GOARCH environment variables if you are targeting some other OS and architecture than your host system (cross-compilation). However, this requires the target system toolchain (compilers, linkers etc.) to work properly. For example see the rpm/libipfs.spec file.

Documentation for go-ipfs Wrapper

The wrapper code itself is in the src folder. The code utilizes callbacks in the case of long running tasks. These tasks are executed as goroutines.

The callbacks are "old style" C callbacks. This means that you can't use fancy new features such as std::bind or std::function when calling the exported functions from C++11 and above. If you wish to bind the callbacks inside C++ classes, you can pass a class instance pointer (or some other pointer) to the wrapper via register_callback_class_instance.

The library exports following functions:

  • ipfs_start
  • ipfs_add_bytes
  • ipfs_add_path_or_file
  • ipfs_ls
  • ipfs_cat
  • ipfs_unpin
  • ipfs_gc
  • ipfs_peers
  • ipfs_id
  • ipfs_repo_stats
  • ipfs_config
  • ipfs_files_cp
  • ipfs_files_ls
  • ipfs_files_mkdir
  • ipfs_files_stat

These functions mirror mostly the go-ipfs command line client methods. The callback will receive both error and possible return values as char*. The return value is encoded as JSON if the function returns more complicated structures than for example single string. See the sources for parameters and the test folder for very basic C command line app example (which needs refactoring...).

Further documentation will be written when the wrapper stabilizes. This depends partially from go-ipfs development since the go-ipfs internal coreapi is not very stable and is missing a lot of features. Therefore, many of the functions use internal stuff from go-ipfs and some functionality is heavily duplicated.

Installation in Sailfish OS SDK

To be able to use this library as a dependency, it needs to be installed to the Sailfish OS build engine. This can be done by logging into the build engine via SSH and running following commmands (change the package name according to the version you wish to install):

i486 target

  1. Download the package: curl -O -L https://github.com/skvark/libipfs/releases/download/0.1.0/libipfs-0.1.0-0.i486.rpm
  2. Install the package: sb2 -t SailfishOS-2.2.0.29-i486 -m sdk-install -R rpm -i libipfs-0.1.0-0.i486.rpm

armv7hl target

  1. Download the package: curl -O -L https://github.com/skvark/libipfs/releases/download/0.1.0/libipfs-0.1.0-0.armv7hl.rpm
  2. Install the package: sb2 -t SailfishOS-2.2.0.29-armv7hl -m sdk-install -R rpm -i libipfs-0.1.0-0.armv7hl.rpm

After installation, go to Sailfish OS-> Targets -> target settings -> Sync. Do this for both targets.

In the project which depends on this library, set the include path in .pro file (so that the libipfs.h header is found). For example on Windows and for armv7hl target:

INCLUDEPATH += C:\SailfishOS\mersdk\targets\SailfishOS-2.2.0.29-armv7hl\usr\include\

Additionally, you'll need to copy the libipfs.so file in the project .spec file to the rpm package and ship it with your application.

About

Simple cgo wrapper for go-ipfs to be used in systems where separate daemons are not allowed or are otherwise suboptimal solution. The primary target is Sailfish OS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published