FreeBSD Setup IPFS Peer to Peer Networking

By using a copy of the data CID or content identifier, IPFS helps you request data from any IPFS node. This process typically involves looking up a distributed hash table and may also require creating new connections to the nodes storing the content.

If you run an IPFS node that serves many requests, such as a public HTTP gateway, IPFS can speed up queries by maintaining long-term connections to IPFS nodes that serve many CIDs. By using IPFS you can prioritize connections to certain peers called Peering. The Peering process will tell IPFS which peers to prioritize by editing the Peering configuration in your IPFS configuration file.

IPFS offers several advantages including faster data transfer, reduced fault tolerance and reduced server load. Not only that, IPFS also has the ability to access data even when disconnected from the Internet or when the data server is not available.

In this article, we will learn how to install and use IPFS on a FreeBSD server. Before we discuss IPFS further, there's no harm in getting to know IPFS first.


1. What is InterPlanetary File System

IPFS (InterPlanetary File System) is a modular suite of protocols protocol establishing the peer-to-peer network with resources addressed based on their content instead of the physical location like in HTTP. IPFS can organizing and transferring data, designed from the ground up with the principles of content addressing and peer-to-peer networking. 

Because IPFS is open-source, there are multiple implementations of IPFS. While IPFS has more than one use case, its main use case is for publishing data (files, directories dan websites) in a decentralised fashion. IPFS gives us some guarantees of blockchains like decentralization and unalterable storage at a fraction of the price you would have to give in transaction fees and participation in the IPFS network is free.

The important part to understand about IPFS is that when you add files via an IPFS node, the IPFS network will not store your files. The added files will remain stored on your computer and other people can read your files. But when you turn off your computer or turn off the IPFS node on your local network, other people cannot read your files, until you are back online. Unless you host files on an external IPFS node, any files you add will remain unreadable by others

While there are storage providers built with IPFS support (typically known as pinning services), IPFS itself is a protocol, not a provider. IPFS can be deployed on and complement cloud infrastructure, but it in of itself is not a cloud service provider.


2. How to Install and Configure IPFS

On FreeBSD IPFS runs in the GO language, so before you install IPFS on your FreeBSD server, the GO Lang application must be installed first. Read the previous article about installing Go Lang on FreeBSD. IPFS on FreeBSD 13.2 can only run with the Go lang version: go119.


After you read the article above, we continue with installing IPFS. If you are using PUTTY, type the command below in the PuTTY shell menu.

Create symlink Go lang
root@ns1:~ # rm -R -f /usr/local/bin/go
root@ns1:~ # ln -s /usr/local/bin/go119 /usr/local/bin/go
Install IPFS with ports FreeBSD.
root@ns6:~ # cd /usr/ports/sysutils/ipfs-go
root@ns6:/usr/ports/sysutils/ipfs-go # make install clean
Run IPFS with the rc.d script, add the script below to the /etc/rc.conf file.

root@ns6:/usr/ports/sysutils/ipfs-go # ee /etc/rc.conf

ipfs_go_enable="YES"
ipfs_go_user="ipfs-go"
ipfs_go_group="ipfs-go"
ipfs_go_path="/var/db/ipfs-go/.ipfs"
ipfs_go_syslog_priority="info"
ipfs_go_syslog_facility="daemon"
ipfs_go_syslog_tag="ipfs-go"
The script above is used to run IPFS automatically on the local computer. Try looking at the script above, in the script we can see that the IPFS configuration file is in the "/var/db/ipfs-go" folder. To make editing easier, use WINSCP, open the folder with WINSCP. Look at the image below.



Open the config file "/var/db/ipfs-go/.ipfs/config", and edit its contents according to the script below.

{
  "API": {
    "HTTPHeaders": {
      "Access-Control-Allow-Methods": [
        "PUT",
        "POST"
      ],
      "Access-Control-Allow-Origin": [
        "http://192.168.5.2:5001",
        "http://localhost:3000",
        "http://127.0.0.1:5001",
        "https://webui.ipfs.io"
      ]
    }
  },
  "Addresses": {
    "API": "/ip4/192.168.5.2/tcp/5001",
    "Announce": [],
    "AppendAnnounce": [],
    "Gateway": "/ip4/192.168.5.2/tcp/8080",
    "NoAnnounce": [],
    "Swarm": [
      "/ip4/0.0.0.0/tcp/4001",
      "/ip6/::/tcp/4001",
      "/ip4/0.0.0.0/udp/4001/quic",
      "/ip4/0.0.0.0/udp/4001/quic-v1",
      "/ip4/0.0.0.0/udp/4001/quic-v1/webtransport",
      "/ip6/::/udp/4001/quic",
      "/ip6/::/udp/4001/quic-v1",
      "/ip6/::/udp/4001/quic-v1/webtransport"
    ]
  },
  "AutoNAT": {},
  "Bootstrap": [
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
    "/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
    "/ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"
  ],
  "DNS": {
    "Resolvers": {}
  },
  "Datastore": {
    "BloomFilterSize": 0,
    "GCPeriod": "1h",
    "HashOnRead": false,
    "Spec": {
      "mounts": [
        {
          "child": {
            "path": "blocks",
            "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
            "sync": true,
            "type": "flatfs"
          },
          "mountpoint": "/blocks",
          "prefix": "flatfs.datastore",
          "type": "measure"
        },
        {
          "child": {
            "compression": "none",
            "path": "datastore",
            "type": "levelds"
          },
          "mountpoint": "/",
          "prefix": "leveldb.datastore",
          "type": "measure"
        }
      ],
      "type": "mount"
    },
    "StorageGCWatermark": 90,
    "StorageMax": "10GB"
  },
  "Discovery": {
    "MDNS": {
      "Enabled": true
    }
  },
  "Experimental": {
    "AcceleratedDHTClient": true,
    "FilestoreEnabled": false,
    "GraphsyncEnabled": false,
    "Libp2pStreamMounting": false,
    "P2pHttpProxy": false,
    "StrategicProviding": false,
    "UrlstoreEnabled": false
  },
  "Gateway": {
    "APICommands": [],
    "HTTPHeaders": {
      "Access-Control-Allow-Headers": [
        "X-Requested-With",
        "Range",
        "User-Agent"
      ],
      "Access-Control-Allow-Methods": [
        "GET"
      ],
      "Access-Control-Allow-Origin": [
        "*"
      ]
    },
    "NoDNSLink": false,
    "NoFetch": false,
    "PathPrefixes": [],
    "PublicGateways": {
      "https://ipfs.io/": {
        "Paths": [
          "/ipfs",
          "/ipns"
        ],
        "UseSubdomains": true
      }
    },
    "RootRedirect": ""
  },
  "Identity": {
    "PeerID": "12D3KooWQkFkABHUCULXkPyRfrLA81dHXgC8evRhdYHWdMRrVcMX",
    "PrivKey": "CAESQNAw3t1E9zNXln5PV5RsoKpK6ewLYMmkNjm0m+5XRNys3dG3lvylqCjlHt88TbEkZDmu5n71YG9JLGMj1gbm5AI="
  },
  "Internal": {},
  "Ipns": {
    "RecordLifetime": "",
    "RepublishPeriod": "",
    "ResolveCacheSize": 128
  },
  "Migration": {
    "DownloadSources": [],
    "Keep": ""
  },
  "Mounts": {
    "FuseAllowOther": false,
    "IPFS": "/ipfs",
    "IPNS": "/ipns"
  },
  "Peering": {
    "Peers": null
  },
  "Pinning": {
    "RemoteServices": {}
  },
  "Plugins": {
    "Plugins": null
  },
  "Provider": {
    "Strategy": ""
  },
  "Pubsub": {
    "DisableSigning": false,
    "Router": ""
  },
  "Reprovider": {},
  "Routing": {
    "Methods": null,
    "Routers": null
  },
  "Swarm": {
    "AddrFilters": null,
    "ConnMgr": {},
    "DisableBandwidthMetrics": false,
    "DisableNatPortMap": false,
    "RelayClient": {},
    "RelayService": {},
    "ResourceMgr": {
      "Limits": {}
    },
    "Transports": {
      "Multiplexers": {},
      "Network": {},
      "Security": {}
    }
  }
}

Pay attention to the blue script, the number 192.168.5.2 is your computer's local IP address. After that we execute the command "ipfs-go init".
root@ns6:~ # ipfs-go init
root@ns6:~ # ipfs-go config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://192.168.5.2:5001", "http://localhost:3000", "http://127.0.0.1:5001", "https://webui.ipfs.io"]'
root@ns6:~ # ipfs-go config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]'
Create symlink IPFS to "/root"
root@ns6:~ # rm -rf /root/.ipfs
root@ns6:~ # ln -s /var/db/ipfs-go/.ipfs /root
Then we create the "/var/db/ipfs-go/.ipfs/api" file.
root@ns6:/var/db/ipfs-go/.ipfs/ipfs # touch /var/db/ipfs-go/.ipfs/api
root@ns6:/var/db/ipfs-go/.ipfs/ipfs # ee /var/db/ipfs-go/.ipfs/api

/ip4/192.168.5.2/tcp/5001
After that we continue by running IPFS.
root@ns6:/var/db/ipfs-go/.ipfs/ipfs # service ipfs-go restart


3. Test IPFS

If everything is configured, the final step is to test whether the IPFS server is running or not. Basic proof of 'ipfs working' locally. The first step we create a folder "/var/db/ipfs-go/.ipfs/ipfs" to store all IPFS data.
root@ns6:~ # mkdir -p /var/db/ipfs-go/.ipfs/ipfs
root@ns6:~ # cd /var/db/ipfs-go/.ipfs/ipfs
root@ns6:/var/db/ipfs-go/.ipfs/ipfs #
After that we create IPFS data, this data will later be used on the peer to peer network via the IPFS Node.
root@ns6:/var/db/ipfs-go/.ipfs/ipfs # echo "FreeBSD IPFS local server" > TestIPFS
root@ns6:/var/db/ipfs-go/.ipfs/ipfs # ipfs-go add TestIPFS
added QmNeCaGW44nddxLZGQmk6GagSafb8gZwcou8YbvhW1wt5b TestIPFS
 26 B / 26 B [==========================================================================================================================================================] 100.00%
root@ns6:/var/db/ipfs-go/.ipfs/ipfs # ipfs-go cat QmNeCaGW44nddxLZGQmk6GagSafb8gZwcou8YbvhW1wt5b
FreeBSD IPFS local server
root@ns6:/var/db/ipfs-go/.ipfs/ipfs #
root@ns6:/var/db/ipfs-go/.ipfs/ipfs # echo "Test IPFS on FreeBSD" > FreeBSDTest.txt
root@ns6:/var/db/ipfs-go/.ipfs/ipfs # ipfs-go add FreeBSDTest.txt
added QmZiaPkqkAsgcCyc84wLnbQnweSj9s2CuJbBSXVzyihshk FreeBSDTest.txt
 21 B / 21 B [==========================================================================================================================================================] 100.00%
root@ns6:/var/db/ipfs-go/.ipfs/ipfs # ipfs-go cat QmZiaPkqkAsgcCyc84wLnbQnweSj9s2CuJbBSXVzyihshk
Test IPFS on FreeBSD
root@ns6:/var/db/ipfs-go/.ipfs/ipfs #
Restart IPFS
root@ns6:/var/db/ipfs-go/.ipfs/ipfs # chown -R ipfs-go:ipfs-go /var/db/ipfs-go/.ipfs/
root@ns6:/var/db/ipfs-go/.ipfs/ipfs # service ipfs-go restart

Now we try to connect to the http ports on the web browser. Open the Google Chrome or Yandex web browser, type "http://192.168.5.2:5001/webui".



Now that you have connected to the IPFS Node, now try typing CIDS from the file "FreeBSDTest.txt dan TestIPFS" that we created previously, pay attention to the blue CIDS above.

In Yandex Browser or Google Chrome enter the following command:

http://192.168.5.2:8080/ipfs/QmNeCaGW44nddxLZGQmk6GagSafb8gZwcou8YbvhW1wt5b
http://192.168.5.2:8080/ipfs/QmZiaPkqkAsgcCyc84wLnbQnweSj9s2CuJbBSXVzyihshk



I'm running an IPFS node on a FreeBSD 13.2 computer and I'm not having any major issues with it, everything is running normally. For programmatic access, you can make your IPFS gateway writable and use the IPFS HTTP API. There are many creative use cases for IPFS.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post