From 269288119db586282d4df3bfb408a31a48ad7315 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 9 Apr 2021 11:28:06 +0300 Subject: [PATCH] [#265] v2/reputation: Support PeerToPeerTrust message Signed-off-by: Leonard Lyubich --- v2/reputation/convert.go | 57 ++++++++++++++++++++++++++++++- v2/reputation/grpc/service.go | 2 +- v2/reputation/grpc/service.pb.go | Bin 39676 -> 39856 bytes v2/reputation/grpc/types.go | 14 ++++++++ v2/reputation/grpc/types.pb.go | Bin 14863 -> 17780 bytes v2/reputation/json.go | 8 +++++ v2/reputation/marshal.go | 39 +++++++++++++++++++++ v2/reputation/message_test.go | 1 + v2/reputation/test/generate.go | 11 +++++- v2/reputation/types.go | 46 +++++++++++++++++++++++-- 10 files changed, 172 insertions(+), 6 deletions(-) diff --git a/v2/reputation/convert.go b/v2/reputation/convert.go index 19be9f03..52df2fa1 100644 --- a/v2/reputation/convert.go +++ b/v2/reputation/convert.go @@ -81,6 +81,61 @@ func (x *Trust) FromGRPCMessage(m grpc.Message) error { return nil } +// ToGRPCMessage converts PeerToPeerTrust to gRPC-generated +// reputation.PeerToPeerTrust message. +func (x *PeerToPeerTrust) ToGRPCMessage() grpc.Message { + var m *reputation.PeerToPeerTrust + + if x != nil { + m = new(reputation.PeerToPeerTrust) + + m.SetTrustingPeer(x.trusting.ToGRPCMessage().(*reputation.PeerID)) + m.SetTrust(x.trust.ToGRPCMessage().(*reputation.Trust)) + } + + return m +} + +// FromGRPCMessage tries to restore PeerToPeerTrust from grpc.Message. +// +// Returns message.ErrUnexpectedMessageType if m is not +// a gRPC-generated reputation.PeerToPeerTrust message. +func (x *PeerToPeerTrust) FromGRPCMessage(m grpc.Message) error { + v, ok := m.(*reputation.PeerToPeerTrust) + if !ok { + return message.NewUnexpectedMessageType(m, v) + } + + var err error + + trusting := v.GetTrustingPeer() + if trusting == nil { + x.trusting = nil + } else { + if x.trusting == nil { + x.trusting = new(PeerID) + } + + err = x.trusting.FromGRPCMessage(trusting) + if err != nil { + return err + } + } + + trust := v.GetTrust() + if trust == nil { + x.trust = nil + } else { + if x.trust == nil { + x.trust = new(Trust) + } + + err = x.trust.FromGRPCMessage(trust) + } + + return err +} + // TrustsToGRPC converts slice of Trust structures // to slice of gRPC-generated Trust messages. func TrustsToGRPC(xs []*Trust) (res []*reputation.Trust) { @@ -404,7 +459,7 @@ func (x *SendIntermediateResultRequestBody) ToGRPCMessage() grpc.Message { m = new(reputation.SendIntermediateResultRequest_Body) m.SetIteration(x.iter) - m.SetTrust(x.trust.ToGRPCMessage().(*reputation.Trust)) + m.SetTrust(x.trust.ToGRPCMessage().(*reputation.PeerToPeerTrust)) } return m diff --git a/v2/reputation/grpc/service.go b/v2/reputation/grpc/service.go index bf8626e6..2104d94c 100644 --- a/v2/reputation/grpc/service.go +++ b/v2/reputation/grpc/service.go @@ -68,7 +68,7 @@ func (x *SendIntermediateResultRequest_Body) SetIteration(v uint32) { } // SetTrust sets current global trust value. -func (x *SendIntermediateResultRequest_Body) SetTrust(v *Trust) { +func (x *SendIntermediateResultRequest_Body) SetTrust(v *PeerToPeerTrust) { if x != nil { x.Trust = v } diff --git a/v2/reputation/grpc/service.pb.go b/v2/reputation/grpc/service.pb.go index fea43eafb3a6a823dd6f408994ca2b8f139a15d5..0116189178d2ba9a344c2f9f6bf554dcf5a68993 100644 GIT binary patch delta 740 zcmYk4NlX(_7{@bBI?z%|LRcnkEiEm!V4>56g3O_di3%-U>`svBUOkX1iNwS$O*|Tn z{JnTF_Npn85Mv}N7mvnxAtmuB(f5WLdU@~rzW4j~_vgKA>w|2o=~hO|<+VhO zp4&|~Bk$BVFV=>b{I)(CWMv))jv`hd^_eLkmd@g1$cS8wg|Eb7FD=gUHl>2U>zTG0 z{+}~WDo?v5OGT3Tv)5B{#))XaD(9z(H^lTXzF$?~VMdEaiNk(OB_rnDjDR-g z185|J__{m_b;?V~Asnn&&|FYpK-5x%7X`+ERnbJ1=c0gDm*&9cEbXCjFa%lbhUNI3 z4q!E?!8dUZC;47H3TRk5N=F{`%kyZZ`?2G*gU_%8v(ae#;(0<2!dup2s-Tc)-htNq zc)NR!Qpcrnyj$w)c1UY*x!{kDU^4f(%}Db+DV-yXj^xxU^K>^ZH(dmiw8NL~ZWhhn&91hcN|{G=Q$K#6{e2y7V3mF)_ z8`R@n;xxQ*9@VT4+6>R=OnitMA#LtCW`1*Y5IY$ayfF(aiZO!bxDKINE7nr|csc8& z7N27+-owfjzXj#+5o~3w41NfE=rRr-Q4Ww6iNb=4ILvD6BEh~-z)#VIL%Fj^WP7k5 z>ZM_AsEZoBDiG8I-FQEyp;wcmjpPWja{@ZzL0PstXJ(UL1UxO38Ozc!Eae5d=23na zpQbuco*YCq&EdM#Avl~glKsBRg~ePP<$|1dBR5LV*~KPp=Z~UU(9r)dw0g{(gI!@a z+NE~nY!=$YOs0CzWHTo1K`Kd^G@mf001RD~I`&*LZ_RTX8otMG#JfYjI z@K1C2=hrgvL5uPhbqroDGI^;e%ik0U4u?5Z#eVgGlew@D;9!I_T-Pe9hIa88uXNh5 Ww_rl{#tHl=^`cf%HORduC;tN-2JM&t diff --git a/v2/reputation/grpc/types.go b/v2/reputation/grpc/types.go index 0a469bd8..07d1d8b4 100644 --- a/v2/reputation/grpc/types.go +++ b/v2/reputation/grpc/types.go @@ -25,6 +25,20 @@ func (x *Trust) SetValue(v float64) { } } +// SetTrustingPeer sets trusting peer ID. +func (x *PeerToPeerTrust) SetTrustingPeer(v *PeerID) { + if x != nil { + x.TrustingPeer = v + } +} + +// SetTrust sets trust value of trusting peer to the trusted one. +func (x *PeerToPeerTrust) SetTrust(v *Trust) { + if x != nil { + x.Trust = v + } +} + // SetManager sets manager ID. func (x *GlobalTrust_Body) SetManager(v *PeerID) { if x != nil { diff --git a/v2/reputation/grpc/types.pb.go b/v2/reputation/grpc/types.pb.go index c2adca51263e3d19acf4c72486db26153b4695b2..7c4ec0471b08820d1ace4baa412ec39ef00020ea 100644 GIT binary patch delta 1465 zcmaJ>OKcle6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