feature/broadcast-trees - #89
Conversation
|
|
||
| func closest(to: Addr) -> Addr? { | ||
|
|
||
| var distance = 0; |
There was a problem hiding this comment.
Lines should not have trailing semicolons.
|
We need to ensure that the last node in the tree, or a node without a “parent” sends the message to all its children. AKA we need to remove the exclude. |
| let packet = Packet.new(topic: Data(topic), type: .subscribe, body: Data(count: 0)) | ||
|
|
||
| XCTAssertEqual(0, transport.sent.count) | ||
| let data = try! packet.serializedData() |
There was a problem hiding this comment.
Force tries should be avoided.
| origin: Addr(repeating: 3, count: 3), | ||
| message: Data(repeating: 0, count: 3) | ||
| ) | ||
| let subscription = try! subscribe.serializedData() |
There was a problem hiding this comment.
Force tries should be avoided.
| let unsubscribe = Packet.new(topic: Data(topic), type: .unsubscribe, body: Data(count: 0)) | ||
|
|
||
| XCTAssertEqual(2, transport.sent.count) | ||
| let data = try! unsubscribe.serializedData() |
There was a problem hiding this comment.
Force tries should be avoided.
| let subscribe = Packet.new(topic: Data(topic), type: .subscribe, body: Data(count: 0)) | ||
|
|
||
| node.send(message) | ||
| let subscription = try! subscribe.serializedData() |
There was a problem hiding this comment.
Force tries should be avoided.
|
code climate is violent, pr looks good, still need to review it further |
| guard let data = try? message.toProto().serializedData() else { | ||
| let packet = Packet.new(topic: Data(topic), type: .message, body: data) | ||
| guard let data = try? packet.serializedData() else { | ||
| // @todo error |
| var distance = 0 | ||
| var addr: Addr? | ||
|
|
||
| forEach { peer in |
There was a problem hiding this comment.
Can just call min(by:) https://developer.apple.com/documentation/swift/array/2298201-min
Much more readable.
|
|
||
| extension Array where Element == Addr { | ||
| func closest(to: Addr) -> Addr? { | ||
| return self.min { a, b in |
There was a problem hiding this comment.
Variable name should be between 3 and 40 characters long: 'a'
|
|
||
| extension Array where Element == Addr { | ||
| func closest(to: Addr) -> Addr? { | ||
| return self.min { a, b in |
There was a problem hiding this comment.
Variable name should be between 3 and 40 characters long: 'b'
|
Code Climate has analyzed commit 6813cdf and detected 0 issues on this pull request. View more on Code Climate. |
closes #88 #51 #56
This PR is currently in draft.
SUBSCRIBE,UNSUBSCRIBEand regularMESSAGESWhat we solve here is how to construct the tree, however we do not solve how messages would be distributed as we can't always directly contact the root.
Also note: Do we need to drop messages that come from a parent who we do not recognize as our parent? Or better said, do we drop messages from peers who are neither our children or parent?
We also need IDs, the current way the Addr works using the Bluetooth Mac will not work. We need the device to have the same ID for all it’s peers.
Another note, when trying to find a parent for a specific node we need to then check if self is closer than parent, if it is self is the parent.