<commit_before>[![Build Status](https://travis-ci.org/ls1intum/sReto.svg)](https://travis-ci.org/ls1intum/sReto)
[![Cocoapods Compatible](https://img.shields.io/cocoapods/v/sReto.svg)](https://img.shields.io/cocoapods/v/sReto.svg)
[![Platform](https://img.shields.io/cocoapods/p/sReto.svg?style=flat)](http://cocoadocs.org/docsets/sReto)
[![Twitter](https://img.shields.io/badge/twitter-@ls1intum-blue.svg?style=flat)](http://twitter.com/ls1intum)

sReto
========
Reto: P2P Framework for realtime collaboration in Swift.

Notice: There is also a Java version for the use of Reto on Windows and Unix: [jReto](https://github.com/ls1intum/jReto)

About
-----

Reto is an extensible P2P networking framework implemented in Swift and Java 8. It offers the same APIs in both languages.

The most important features of the framework are:

  - Peer discovery
  - Establishing connections between peers
  - Performing cancellable data transfers
  - Offers support for routed connections (i.e., peers that can not directly communicate can still be discovered and use other peers to forward data)

Reto is designed to be easily extensible to use other networking technologies by implementing Reto "Module"s; by default, it comes with two modules:

  - WlanModule: Enables peer discovery and connectivity in local area networks by using Bonjour for discovery and standard TCP/IP connections for data transfers
  - RemoteP2PModule: Uses an online server to facilitate communication between peers. This module enables peers to discover each other and communicate over the Internet; however, a RemoteP2P server is required. 


Installation
------------

Reto is provided as a standard Xcode project that includes framework targets for Reto on iOS and Mac OS X. Even though it is implemented in Swift, it can be used in both Objective C and Swift projects. Here are the steps required to include Reto (using Xcode 6.1).

 1. Open the Xcode project in which you want to include Reto. Drag & drop the sReto.xcodeproj into your project.
 2. Select your project and add sReto in as a target dependency and link your project with it in the "Build Phases" tab.
 3. Import the module in your code:
  1. In Swift, import Reto using "import sReto" depending on your target platform.
  2. In Objective-C, import Reto using "@import sReto;"
 
Usage
-----

**Starting Discovery/Advertisement**

Advertisement and discovery is managed by the `LocalPeer` class. A `LocalPeer` requires one or more Reto Modules to function. In this example, we will use the `WlanModule`.

*Swift*

```swift
// 1. Create the WlanModule
let wlanModule = WlanModule(type: "ExampleType", dispatchQueue: dispatch_get_main_queue())
// 2. Create the LocalPeer
let localPeer = LocalPeer(modules: [wlanModule], dispatchQueue: dispatch_get_main_queue())
// 3. Starting the LocalPeer
localPeer.start(
  onPeerDiscovered: { peer in print("Discovered peer: \(peer)") },
  onPeerRemoved: { peer in print("Removed peer: \(peer)") },
  onIncomingConnection: { peer, connection in print("Received incoming connection: \(connection) from peer: \(peer)"") },
  displayName: "MyLocalPeer"
)
```

*Objective C*

```objc
// 1. Create the WlanModule
WlanModule* wlanModule = [[WlanModule alloc] initWithType: "ExampleType" dispatchQueue: dispatch_get_main_queue()];
// 2. Create the LocalPeer
LocalPeer* localPeer = [[LocalPeer alloc] initWithModules: @[wlanModule] dispatchQueue: dispatch_get_main_queue())<commit_msg>update installation in README<commit_after>[![Build Status](https://travis-ci.org/ls1intum/sReto.svg)](https://travis-ci.org/ls1intum/sReto)
[![Cocoapods Compatible](https://img.shields.io/cocoapods/v/sReto.svg)](https://img.shields.io/cocoapods/v/sReto.svg)
[![Platform](https://img.shields.io/cocoapods/p/sReto.svg?style=flat)](http://cocoadocs.org/docsets/sReto)
[![Twitter](https://img.shields.io/badge/twitter-@ls1intum-blue.svg?style=flat)](http://twitter.com/ls1intum)

sReto
========
Reto: P2P Framework for realtime collaboration in Swift.

Notice: There is also a Java version for the use of Reto on Windows and Unix: [jReto](https://github.com/ls1intum/jReto)

About
-----

Reto is an extensible P2P networking framework implemented in Swift and Java 8. It offers the same APIs in both languages.

The most important features of the framework are:

  - Peer discovery
  - Establishing connections between peers
  - Performing cancellable data transfers
  - Offers support for routed connections (i.e., peers that can not directly communicate can still be discovered and use other peers to forward data)

Reto is designed to be easily extensible to use other networking technologies by implementing Reto "Module"s; by default, it comes with two modules:

  - WlanModule: Enables peer discovery and connectivity in local area networks by using Bonjour for discovery and standard TCP/IP connections for data transfers
  - RemoteP2PModule: Uses an online server to facilitate communication between peers. This module enables peers to discover each other and communicate over the Internet; however, a RemoteP2P server is required. 


Installation
------------

The recommended approach for installing sReto is via the [CocoaPods](http://cocoapods.org) package manager, as it provides flexible dependency management.

sReto can be integrated as framework on iOS 8.0+ and OS X 10.9+. Even though it is implemented in Swift, it can be used in both Objective C and Swift projects. Here are the steps required to include Reto using CocoaPods.

### via CocoaPods

Install CocoaPods if not already available:

``` bash
$ [sudo] gem install cocoapods
$ pod setup
```

Change to the directory of your Xcode project, and Create and Edit your Podfile and add sReto:

``` bash
$ cd /path/to/MyProject
$ pod init
$ edit Podfile
platform :ios, '8.0'
# Or platform :osx, '10.9'
pod 'sReto'
# this will install the WLAN module and all its dependencies

# Bluetooth and Remote are optional modules
pod 'sReto/BluetoothModule'
pod 'sReto/RemoteModule'

# Alternatively you can also install all modules with:
pod 'sReto/AllModules'

```

Install into your project:

``` bash
$ pod install
```

Open your project in Xcode from the .xcworkspace file (not the usual project file)

``` bash
$ open MyProject.xcworkspace
```

Import the module in your code:
  1. In Swift, import Reto using "import sReto" depending on your target platform.
  2. In Objective-C, import Reto using "@import sReto;"

Please note that if your installation fails, it may be because you are installing with a version of Git lower than CocoaPods is expecting. Please ensure that you are running Git **>= 1.8.0** by executing `git --version`. You can get a full picture of the installation details by executing `pod install --verbose`.

 
Usage
-----

**Starting Discovery/Advertisement**

Advertisement and discovery is managed by the `LocalPeer` class. A `LocalPeer` requires one or more Reto Modules to function. In this example, we will use the `WlanModule`.

*Swift*

```swift
// 1. Create the WlanModule
let wlanModule = WlanModule(type: "ExampleType", dispatchQueue: dispatch_get_main_queue())
// 2. Create the LocalPeer
let localPeer = LocalPeer(modules: [wlanModule], dispatchQueue: dispatch_get_main_queue())
// 3. Starting the LocalPeer
localPeer.start(
  onPeerDiscovered: { peer in print("Discovered peer: \(peer)") },
  onPeerRemoved: { peer in print("Removed peer: \(peer)") },
  onIncomingConnection: { peer, connection in print("Received incoming connection: \(connection) from peer: \(peer)"") },
  displayName: "MyLocalPeer"
)
```

*Objective C*

```objc
// 1. Create the WlanModule
WlanModule* wlanModule = [[WlanModule alloc] initWithType: "ExampleType" dispatchQueue: dispatch_get_main_queue()];
// 2. Create the LocalPeer
LocalPeer* localPeer = [[LocalPeer alloc] initWithModules: @[wlanModule] dispatchQueue: dispatch_get_main_queue())
{'fraction_non_alphanumeric': 0.09942784488239034, 'fraction_numerical': 0.006611570247933884, 'mean_word_length': 4.663066954643629, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1480180', 'n_tokens_mistral': 2407, 'n_tokens_neox': 2257, 'n_words': 918}