-
Notifications
You must be signed in to change notification settings - Fork 2
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
Closed
feature/services #71
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f109d81
added service handling
decanus 3f597b1
update
decanus 63e75de
minor
decanus ac213d2
format
decanus ab6b133
Merge branch 'master' into feature/services
decanus fa6a78b
renamed
decanus 87e2bf6
Merge branch 'feature/services' of github.com:ultralight-beam/UB.swif…
decanus 7dec7ad
Merge branch 'master' into feature/services
decanus a5baead
Merge branch 'master' into feature/services
decanus 3fb0d20
updated
decanus 295eb09
doc
decanus cb42af8
fix
decanus 848365b
Merge branch 'master' into feature/services
decanus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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? | ||
|
||
|
@@ -35,11 +38,20 @@ 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) | ||
} | ||
|
||
public func add(service: Service) { | ||
let id = service.identifier | ||
if services[id] != nil { | ||
return | ||
} | ||
|
||
transports.removeValue(forKey: transport) | ||
services[id] = service | ||
} | ||
|
||
public func remove(service: UBID) { | ||
services.removeValue(forKey: service) | ||
} | ||
|
||
/// Sends a message through the current transports. | ||
|
@@ -100,17 +112,31 @@ 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 | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Limit vertical whitespace to a single empty line. Currently 2. |
||
return send(message) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Foundation | ||
|
||
public protocol Service: NodeDelegate { | ||
/// The unique service identifier. | ||
var identifier: UBID { get } | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limit vertical whitespace to a single empty line. Currently 2.