ml-trust-model

git clone git://git.codymlewis.com/ml-trust-model.git
Log | Files | Refs | README

commit 6517f712182cef1c73beedfea34a5a268f2a3da5
parent fd46cada9849e23328b255479a8bd21599f84a64
Author: Cody Lewis <codymlewis@protonmail.com>
Date:   Wed, 13 Mar 2019 13:12:59 +1100

Added a bad mouther class

Diffstat:
MTest.py | 23+++++++++++++++++++++++
MTrustModel.py | 8++++++++
2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/Test.py b/Test.py @@ -72,6 +72,29 @@ class TestTrustModel(unittest.TestCase): self.assertEqual(no_of_nodes * constrained_nodes, num_constrained) self.assertEqual(no_of_nodes * poor_witnesses, num_poor_witnesses) + def test_bad_mouther(self): + ''' + Test the report creation of the bad mouther. + ''' + proxy = TrustModel.Node(100, 100) + bad_mouther = TrustModel.BadMouther() + self.make_report(bad_mouther, proxy, note=-1) + proxy = TrustModel.Node(1, 100) + self.make_report(bad_mouther, proxy, note=-1) + proxy = TrustModel.Node(100, 1) + self.make_report(bad_mouther, proxy, note=-1) + proxy = TrustModel.Node(1, 1) + self.make_report(bad_mouther, proxy, note=-1) + + def make_report(self, client, proxy, service=50, capability=50, note=1): + ''' + Test that a report matches expected values + ''' + report = client.send_report(proxy, service, capability) + self.assertEqual(report.service, service) + self.assertEqual(report.capability, capability) + self.assertEqual(report.note, note) + if __name__ == '__main__': unittest.main() diff --git a/TrustModel.py b/TrustModel.py @@ -52,6 +52,14 @@ class Node: return wrong_note(note) +class BadMouther(Node): + ''' + A bad mouthing malicious node. + ''' + def take_note(self, proxy, service_target, capability_target): + return -1 + + class TrustManager: ''' Create and control the network.