Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/services #71

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.1)
activesupport (4.2.11.1)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
atomos (0.1.3)
claide (1.0.3)
cocoapods (1.7.5)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.7.5)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.2.2, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-stats (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.3.1, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.6.6)
nap (~> 1.0)
ruby-macho (~> 1.4)
xcodeproj (>= 1.10.0, < 2.0)
cocoapods-core (1.7.5)
activesupport (>= 4.0.2, < 6)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.2.2)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
cocoapods-stats (1.1.0)
cocoapods-trunk (1.4.0)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.1.0)
colored2 (3.1.2)
concurrent-ruby (1.1.5)
escape (0.0.4)
ffi (1.11.1)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jazzy (0.11.1)
cocoapods (~> 1.5)
mustache (~> 1.1)
open4
redcarpet (~> 3.4)
rouge (>= 2.0.6, < 4.0)
sassc (~> 2.1)
sqlite3 (~> 1.3)
xcinvoke (~> 0.3.0)
liferaft (0.0.6)
minitest (5.11.3)
molinillo (0.6.6)
mustache (1.1.0)
nanaimo (0.2.6)
nap (1.1.0)
netrc (0.11.0)
open4 (1.3.4)
redcarpet (3.5.0)
rouge (2.0.7)
ruby-macho (1.4.0)
sassc (2.2.1)
ffi (~> 1.9)
sqlite3 (1.4.1)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
xcinvoke (0.3.0)
liferaft (~> 0.0.6)
xcodeproj (1.12.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.2.6)
xcpretty (0.3.0)
rouge (~> 2.0.7)

PLATFORMS
ruby

DEPENDENCIES
jazzy (= 0.11.1)
xcpretty

BUNDLED WITH
1.17.2
45 changes: 38 additions & 7 deletions Sources/UB/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public class Node {
/// The known transports for the node.
public private(set) var transports = [String: Transport]()

/// The known services for the node.
public private(set) var services = [UBID: Service]()

/// The nodes delegate.
public weak var delegate: NodeDelegate?

Expand Down Expand Up @@ -35,11 +38,28 @@ public class Node {
/// - Parameters:
/// - transport: The identifier of the transport to remove.
public func remove(transport: String) {
guard transports[transport] != nil else {
transports.removeValue(forKey: transport)
}

/// Adds a new service to the list of known service.
///
/// - Parameters:
/// - service: The service to be added.
public func add(service: Service) {
let id = service.identifier
if services[id] != nil {
return
}

transports.removeValue(forKey: transport)
services[id] = service
}

/// Removes a service from the list of known service.
///
/// - Parameters:
/// - service: The identifier of the service to remove.
public func remove(service: UBID) {
services.removeValue(forKey: service)
}

/// Sends a message through the current transports.
Expand Down Expand Up @@ -100,17 +120,28 @@ public class Node {
/// :nodoc:
extension Node: TransportDelegate {
public func transport(_: Transport, didReceiveData data: Data, from: Addr) {
// @todo message should probably be created here

// @todo delegate should return something where we handle retransmission.

// @todo if node delegate doesn't return anything success, send out the message?

guard let packet = try? Packet(serializedData: data) else {
// @todo
return
}

delegate?.node(self, didReceiveMessage: Message(protobuf: packet, from: from))
let message = Message(protobuf: packet, from: from)

if message.service.count > 0 {
if let service = services[message.service] {
return service.node(self, didReceiveMessage: message) // @todo maybe status check?
}
}

// @todo check if we are the recipient else retransmit
// if node.identity == message.recipient {
// return delegate?.node(self, didReceiveMessage: message) // @todo maybe status check
// }

// @todo retransmit if we don't have the service

return send(message)
}
}
7 changes: 7 additions & 0 deletions Sources/UB/Service.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

/// Services are responsible for handling messages received from an Ultralight Beam node.
public protocol Service: NodeDelegate {
/// The unique service identifier.
var identifier: UBID { get }
}
2 changes: 1 addition & 1 deletion docs/Classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-02)</p>
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-14)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.11.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/Classes/CoreBluetoothTransport.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-02)</p>
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-14)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.11.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
121 changes: 120 additions & 1 deletion docs/Classes/Node.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,33 @@ <h4>Declaration</h4>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:2UB4NodeC8servicesXevp"></a>
<a name="//apple_ref/swift/Property/services" class="dashAnchor"></a>
<a class="token" href="#/s:2UB4NodeC8servicesXevp">services</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The known services for the node.</p>

</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">private(set)</span> <span class="k">var</span> <span class="nv">services</span><span class="p">:</span> <span class="o">&lt;&lt;</span><span class="n">error</span> <span class="n">type</span><span class="o">&gt;&gt;</span></code></pre>

</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
Expand Down Expand Up @@ -266,6 +293,98 @@ <h4>Parameters</h4>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:2UB4NodeC3addyyXe_tcACF"></a>
<a name="//apple_ref/swift/Method/add(service:)" class="dashAnchor"></a>
<a class="token" href="#/s:2UB4NodeC3addyyXe_tcACF">add(service:)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Adds a new service to the list of known service.</p>

</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">add</span><span class="p">(</span><span class="nv">service</span><span class="p">:</span> <span class="kt">Service</span><span class="p">)</span></code></pre>

</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>service</em>
</code>
</td>
<td>
<div>
<p>The service to be added.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:2UB4NodeC6remove7serviceySays5UInt8VG_tF"></a>
<a name="//apple_ref/swift/Method/remove(service:)" class="dashAnchor"></a>
<a class="token" href="#/s:2UB4NodeC6remove7serviceySays5UInt8VG_tF">remove(service:)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Removes a service from the list of known service.</p>

</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">remove</span><span class="p">(</span><span class="nv">service</span><span class="p">:</span> <span class="kt"><a href="../Typealiases.html#/s:2UB4UBIDa">UBID</a></span><span class="p">)</span></code></pre>

</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>service</em>
</code>
</td>
<td>
<div>
<p>The identifier of the service to remove.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
Expand Down Expand Up @@ -317,7 +436,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-02)</p>
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-14)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.11.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/Classes/Peer.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-02)</p>
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-14)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.11.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-02)</p>
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-14)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.11.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols/NodeDelegate.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-02)</p>
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-14)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.11.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols/Transport.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-02)</p>
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-14)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.11.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols/TransportDelegate.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-02)</p>
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-14)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.11.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/Structs.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-02)</p>
<p>&copy; 2019 <a class="link" href="http://ultralightbeam.io" target="_blank" rel="external">Ultralight Beam</a>. All rights reserved. (Last updated: 2019-10-14)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.11.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
Loading