Package ipfs.gomobile.android
Class IPFS
- java.lang.Object
-
- ipfs.gomobile.android.IPFS
-
public class IPFS extends java.lang.Object
IPFS is a class that wraps a go-ipfs node and its shell over UDS.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IPFS.ConfigCreationException
static class
IPFS.ConfigGettingException
static class
IPFS.ConfigSettingException
static class
IPFS.ExtraOptionException
static class
IPFS.NodeListenException
static class
IPFS.NodeStartException
static class
IPFS.NodeStopException
static class
IPFS.RepoInitException
static class
IPFS.RepoOpenException
static class
IPFS.ShellRequestException
static class
IPFS.SockManagerException
-
Constructor Summary
Constructors Constructor Description IPFS(android.content.Context context)
Class constructor using defaultRepoPath "/ipfs/repo" on internal storage.IPFS(android.content.Context context, java.lang.String repoPath)
Class constructor using repoPath passed as parameter on internal storage.IPFS(android.content.Context context, java.lang.String repoPath, boolean internalStorage)
Class constructor using repoPath and storage location passed as parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.json.JSONObject
getConfig()
Gets the IPFS instance config as a JSON.org.json.JSONObject
getConfigKey(java.lang.String key)
Gets the JSON value associated to the key passed as parameter in the IPFS instance config.java.lang.String
getRepoAbsolutePath()
Returns the repo absolute path as a string.boolean
isStarted()
Returns true if this IPFS instance is "started" by checking if the underlying go-ipfs node is instantiated.RequestBuilder
newRequest(java.lang.String command)
Creates and returns a RequestBuilder associated to this IPFS instance shell.void
restart()
Restarts this IPFS instance.java.lang.String
serveGatewayMultiaddr(java.lang.String multiaddr, java.lang.Boolean writable)
Serves node gateway over the given multiaddrvoid
setConfig(org.json.JSONObject config)
Sets JSON config passed as parameter as IPFS config or reset to default config (with a new identity) if the config parameter is null.
A started instance must be restarted for its config to be applied.void
setConfigKey(java.lang.String key, org.json.JSONObject value)
Sets JSON config value to the key passed as parameters in the IPFS instance config.
A started instance must be restarted for its config to be applied.void
start()
Starts this IPFS instance.void
stop()
Stops this IPFS instance.
-
-
-
Constructor Detail
-
IPFS
public IPFS(@NonNull android.content.Context context) throws IPFS.ConfigCreationException, IPFS.RepoInitException, IPFS.SockManagerException
Class constructor using defaultRepoPath "/ipfs/repo" on internal storage.- Parameters:
context
- The application context- Throws:
IPFS.ConfigCreationException
- If the creation of the config failedIPFS.RepoInitException
- If the initialization of the repo failedIPFS.SockManagerException
- If the initialization of SockManager failed
-
IPFS
public IPFS(@NonNull android.content.Context context, @NonNull java.lang.String repoPath) throws IPFS.ConfigCreationException, IPFS.RepoInitException, IPFS.SockManagerException
Class constructor using repoPath passed as parameter on internal storage.- Parameters:
context
- The application contextrepoPath
- The path of the go-ipfs repo (relative to internal root)- Throws:
IPFS.ConfigCreationException
- If the creation of the config failedIPFS.RepoInitException
- If the initialization of the repo failedIPFS.SockManagerException
- If the initialization of SockManager failed
-
IPFS
public IPFS(@NonNull android.content.Context context, @NonNull java.lang.String repoPath, boolean internalStorage) throws IPFS.ConfigCreationException, IPFS.RepoInitException, IPFS.SockManagerException
Class constructor using repoPath and storage location passed as parameters.- Parameters:
context
- The application contextrepoPath
- The path of the go-ipfs repo (relative to internal/external root)internalStorage
- true, if the desired storage location for the repo path is internal false, if the desired storage location for the repo path is external- Throws:
IPFS.ConfigCreationException
- If the creation of the config failedIPFS.RepoInitException
- If the initialization of the repo failedIPFS.SockManagerException
- If the initialization of SockManager failed
-
-
Method Detail
-
getRepoAbsolutePath
public java.lang.String getRepoAbsolutePath()
Returns the repo absolute path as a string.- Returns:
- The repo absolute path
-
isStarted
public boolean isStarted()
Returns true if this IPFS instance is "started" by checking if the underlying go-ipfs node is instantiated.- Returns:
- true, if this IPFS instance is started
-
start
public void start() throws IPFS.NodeStartException
Starts this IPFS instance. Also serve config Gateway and API located inside the config (if any)- Throws:
IPFS.NodeStartException
- If the node is already started or if its startup fails
-
stop
public void stop() throws IPFS.NodeStopException
Stops this IPFS instance.- Throws:
IPFS.NodeStopException
- If the node is already stopped or if its stop fails
-
restart
public void restart() throws IPFS.NodeStopException
Restarts this IPFS instance.- Throws:
IPFS.NodeStopException
- If the node is already stopped or if its stop fails
-
getConfig
public org.json.JSONObject getConfig() throws IPFS.ConfigGettingException
Gets the IPFS instance config as a JSON.- Returns:
- The IPFS instance config as a JSON
- Throws:
IPFS.ConfigGettingException
- If the getting of the config failed- See Also:
- IPFS Config Doc
-
setConfig
public void setConfig(org.json.JSONObject config) throws IPFS.ConfigSettingException
Sets JSON config passed as parameter as IPFS config or reset to default config (with a new identity) if the config parameter is null.
A started instance must be restarted for its config to be applied.- Parameters:
config
- The IPFS instance JSON config to set (if null, default config will be used)- Throws:
IPFS.ConfigSettingException
- If the setting of the config failed- See Also:
- IPFS Config Doc
-
getConfigKey
public org.json.JSONObject getConfigKey(@NonNull java.lang.String key) throws IPFS.ConfigGettingException
Gets the JSON value associated to the key passed as parameter in the IPFS instance config.- Parameters:
key
- The key associated to the value to get in the IPFS config- Returns:
- The JSON value associated to the key passed as parameter in the IPFS instance config
- Throws:
IPFS.ConfigGettingException
- If the getting of the config value failed- See Also:
- IPFS Config Doc
-
setConfigKey
public void setConfigKey(@NonNull java.lang.String key, @NonNull org.json.JSONObject value) throws IPFS.ConfigSettingException
Sets JSON config value to the key passed as parameters in the IPFS instance config.
A started instance must be restarted for its config to be applied.- Parameters:
key
- The key associated to the value to set in the IPFS instance configvalue
- The JSON value associated to the key to set in the IPFS instance config- Throws:
IPFS.ConfigSettingException
- If the setting of the config value failed- See Also:
- IPFS Config Doc
-
newRequest
public RequestBuilder newRequest(@NonNull java.lang.String command) throws IPFS.ShellRequestException
Creates and returns a RequestBuilder associated to this IPFS instance shell.- Parameters:
command
- The command of the request- Returns:
- A RequestBuilder based on the command passed as parameter
- Throws:
IPFS.ShellRequestException
- If this IPFS instance is not started- See Also:
- IPFS API Doc
-
serveGatewayMultiaddr
public java.lang.String serveGatewayMultiaddr(@NonNull java.lang.String multiaddr, @NonNull java.lang.Boolean writable) throws IPFS.NodeListenException
Serves node gateway over the given multiaddr- Parameters:
multiaddr
- The multiaddr to listen onwritable
- If true: will also support support `POST`, `PUT`, and `DELETE` methods.- Returns:
- The MultiAddr the node is serving on
- Throws:
IPFS.NodeListenException
- If the node failed to serve- See Also:
- IPFS Doc
-
-