Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
  • Loading branch information
gfanton authored and n0izn0iz committed Jan 29, 2022
1 parent 013bc9d commit f166213
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 11 deletions.
35 changes: 28 additions & 7 deletions android/bridge/src/main/java/ipfs/gomobile/android/IPFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ synchronized public void start() throws NodeStartException {
node.serveUnixSocketAPI(absSockPath);

// serve config Addresses API & Gateway
node.serve();
node.serveConfig();
} catch (Exception e) {
throw new NodeStartException("Node start failed", e);
}
Expand Down Expand Up @@ -315,18 +315,35 @@ synchronized public RequestBuilder newRequest(@NonNull String command)
return new RequestBuilder(requestBuilder);
}

/**
/**
* Serves node gateway over the given multiaddr
*
* @param multiaddr The multiaddr to listen on
* @param writable If true: will also support support `POST`, `PUT`, and `DELETE` methods.
* @return The MultiAddr the node is serving on
* @throws NodeListenException If the node failed to serve
* @see <a href="https://docs.ipfs.io/concepts/ipfs-gateway/#gateway-providers">IPFS Doc</a>
*/
synchronized public String serveGatewayMultiaddr(@NonNull String multiaddr, @NonNull Boolean writable) throws NodeListenException {
try {
return node.serveGatewayMultiaddr(multiaddr, writable);
} catch (Exception e) {
throw new NodeListenException("failed to listen on gateway", e);
}
}

/**
* Sets the primary and secondary DNS for gomobile (hacky, will be removed in future version)
*
* @param primary The primary DNS address in the form {@code <ip4>:<port>}
* @param secondary The secondary DNS address in the form {@code <ip4>:<port>}
*/
public static void setDNSPair(@NonNull String primary, @NonNull String secondary) {
Objects.requireNonNull(primary, "primary should not be null");
Objects.requireNonNull(secondary, "secondary should not be null");
public static void setDNSPair(@NonNull String primary, @NonNull String secondary) {
Objects.requireNonNull(primary, "primary should not be null");
Objects.requireNonNull(secondary, "secondary should not be null");

Core.setDNSPair(primary, secondary, false);
}
Core.setDNSPair(primary, secondary, false);
}

/**
* Internal helper that opens the repo if it is closed.
Expand All @@ -348,6 +365,10 @@ public static class ExtraOptionException extends Exception {
ExtraOptionException(String message, Throwable err) { super(message, err); }
}

public static class NodeListenException extends Exception {
NodeListenException(String message, Throwable err) { super(message, err); }
}

public static class ConfigCreationException extends Exception {
ConfigCreationException(String message, Throwable err) { super(message, err); }
}
Expand Down
17 changes: 15 additions & 2 deletions ios/Bridge/GomobileIPFS/Sources/IPFS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public class IPFS {

// Create a shell over UDS on physical device
#if !targetEnvironment(simulator)
try self.node!.serve(onUDS: self.absSockPath)
try self.node!.serveAPI(onUDS: self.absSockPath)
self.shell = CoreNewUDSShell(self.absSockPath)
/*
** On iOS simulator, temporary directory's absolute path exceeds
** the length limit for Unix Domain Socket, since simulator is
** only used for debug, we can safely fallback on shell over TCP
*/
#else
let maddr: String = try self.node!.serve(onTCPPort: "0")
let maddr: String = try self.node!.serveAPI(onTCPPort: "0")
self.shell = CoreNewShell(maddr)
#endif

Expand Down Expand Up @@ -203,6 +203,19 @@ public class IPFS {
return RequestBuilder(requestBuilder)
}

/// Serves node Gateway over the given Multiaddr
/// - Parameter onMultiaddr: The multiaddr to serve on
/// - Parameter writable: If true: will also support support `POST`, `PUT`, and `DELETE` methods.
/// - Throws: `NodeError`: If the node failed to serve
public func serveGateway(onMultiaddr: String, _ writable: Bool = false) throws -> String{
guard let node = self.node else {
throw IPFSError("unable to serve the gateway, is the node started?")
}

return try node.serveGateway(onMultiaddr: onMultiaddr, writable: writable)
}


/// Sets the primary and secondary DNS for gomobile (hacky, will be removed in future version)
/// - Parameters:
/// - primary: The primary DNS address in the form `<ip4>:<port>`
Expand Down
19 changes: 17 additions & 2 deletions ios/Bridge/GomobileIPFS/Sources/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Node {
/// Serves node API over UDS
/// - Parameter onUDS: The UDS path to serve on
/// - Throws: `NodeError`: If the node failed to serve
public func serve(onUDS: String) throws {
public func serveAPI(onUDS: String) throws {
do {
try self.node.serveUnixSocketAPI(onUDS)
} catch let error as NSError {
Expand All @@ -66,7 +66,7 @@ public class Node {
/// - Parameter onTCPPort: The TCP port to serve on
/// - Throws: `NodeError`: If the node failed to serve
/// - Returns: The TCP/IP MultiAddr the node is serving on
public func serve(onTCPPort: String) throws -> String {
public func serveAPI(onTCPPort: String) throws -> String {
var err: NSError?

let maddr = self.node.serveTCPAPI(onTCPPort, error: &err)
Expand All @@ -78,6 +78,21 @@ public class Node {
return maddr
}

/// Serves node Gateway over the given Multiaddr
/// - Parameter onMultiaddr: The multiaddr to serve on
/// - Parameter writable: If true: will also support support `POST`, `PUT`, and `DELETE` methods.
/// - Throws: `NodeError`: If the node failed to serve
public func serveGateway(onMultiaddr: String, writable: Bool = false) throws -> String{
var err: NSError?

let maddr = self.node.serveGatewayMultiaddr(onMultiaddr, writable: writable, error: &err)
if err != nil {
throw NodeError("unable to serve gateway on \(onMultiaddr)", err)
}

return maddr
}

/// Serves any multiaddr (api & gateway) inside `Addresses.Api` and
/// `Addresses.Gateway` in the config (if any)
/// - Throws: `NodeError`: If the node failed to serve
Expand Down

0 comments on commit f166213

Please sign in to comment.