Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Adding README and adding dict_dir to the parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ineiti committed Jul 8, 2021
1 parent 8da9bc3 commit 0193323
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,46 @@ This version comes with a mandatory cache of the tor directory data.
This means that the app itself will have to download this data and make
it available in a directory to the library.

For more information, see [Directory Cache](https://github.com/c4dt/arti-rest/blob/directory_scripts/tools/README.md)
For more information, see [Directory Cache](https://github.com/c4dt/arti-rest/blob/directory_scripts/tools/README.md)

There is a daily tor-directory update here:
[arti-directory](https://github.com/c4dt/arti-directory)

# API

The `arti-ios` library exposes one call:

```
/**
Makes a synchronous call to the arti library to fetch the given url with the indicated method.
The arti backend will
set up a new circuit over tor and send the request over this circuit.
In case of an error in the arti library, an ArtiError is thrown.
REST errors are returned through the 'status' field of the ReturnStruct.
- Parameters:
- method: one of the ARtiMethods
- url: the destination of the request
- headers: of the request
- body: data to be sent along
- Returns: a ReturnStruct with the result
- Throws: `ArtiError` in case something within the arti-library produced an error
*/
public func callArti(method: ArtiMethods, url: String,
headers: [String: [String]] = [:],
body: Data = Data([])) throws -> ReturnStruct
```

The `ReturnStruct` has the following definition:

```
public struct ReturnStruct {
public var status: UInt16
public var headers: [String: [String]]
public var body: Data
}
```

Any REST-request error returns successfully, but the `status` field will be set to an error-code.
26 changes: 19 additions & 7 deletions Sources/arti-ios/arti_ios.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,29 @@ public enum ArtiMethods {
}

/**
* Makes a synchronous call to the arti library to fetch the given url with the indicated method. The arti backend will
* set up a new circuit over tor and send the request over this circuit.
* In case of an error in the arti library, an ArtiError is thrown.
* REST errors are returned through the 'status' field of the ReturnStruct.
Makes a synchronous call to the arti library to fetch the given url with the indicated method.
The arti backend will
set up a new circuit over tor and send the request over this circuit.
In case of an error in the arti library, an ArtiError is thrown.
REST errors are returned through the 'status' field of the ReturnStruct.
- Parameters:
- dict_dir:
- method: one of the ARtiMethods
- url: the destination of the request
- headers: of the request
- body: data to be sent along
- Returns: a ReturnStruct with the result
- Throws: `ArtiError` in case something within the arti-library produced an error
*/
public func callArti(method: ArtiMethods, url: String,
public func callArti(dict_dir: String,
method: ArtiMethods, url: String,
headers: [String: [String]] = [:],
body: Data = Data([])) throws -> ReturnStruct {
let resourcePath = Bundle.main.resourcePath!
let ar = ArtiRequest(method: "\(method)", url: url, headers: headers,
body: [UInt8](body), dict_dir: resourcePath + "/directory");
body: [UInt8](body), dict_dir: dict_dir);
let ar_str = String(data: try JSONEncoder().encode(ar), encoding: .utf8);
let ret_json = call_arti(ar_str).takeRetainedValue() as NSString as String;

Expand Down

0 comments on commit 0193323

Please sign in to comment.