Merge remote-tracking branch 'origin/master' into update/next-master

This commit is contained in:
Łukasz Magiera
2020-08-07 05:09:26 +02:00
8 changed files with 295 additions and 47 deletions
+6 -6
View File
@@ -174,13 +174,13 @@ func (t *LatencyMessage) MarshalCBOR(w io.Writer) error {
scratch := make([]byte, 9)
// t.TArrial (int64) (int64)
if t.TArrial >= 0 {
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TArrial)); err != nil {
// t.TArrival (int64) (int64)
if t.TArrival >= 0 {
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TArrival)); err != nil {
return err
}
} else {
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.TArrial-1)); err != nil {
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.TArrival-1)); err != nil {
return err
}
}
@@ -216,7 +216,7 @@ func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.TArrial (int64) (int64)
// t.TArrival (int64) (int64)
{
maj, extra, err := cbg.CborReadHeaderBuf(br, scratch)
var extraI int64
@@ -239,7 +239,7 @@ func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for int64 field: %d", maj)
}
t.TArrial = int64(extraI)
t.TArrival = int64(extraI)
}
// t.TSent (int64) (int64)
{
+6 -6
View File
@@ -34,8 +34,8 @@ type HelloMessage struct {
GenesisHash cid.Cid
}
type LatencyMessage struct {
TArrial int64
TSent int64
TArrival int64
TSent int64
}
type NewStreamFunc func(context.Context, peer.ID, ...protocol.ID) (inet.Stream, error)
@@ -86,8 +86,8 @@ func (hs *Service) HandleStream(s inet.Stream) {
sent := build.Clock.Now()
msg := &LatencyMessage{
TArrial: arrived.UnixNano(),
TSent: sent.UnixNano(),
TArrival: arrived.UnixNano(),
TSent: sent.UnixNano(),
}
if err := cborutil.WriteCborRPC(s, msg); err != nil {
log.Debugf("error while responding to latency: %v", err)
@@ -171,8 +171,8 @@ func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
}
if err == nil {
if lmsg.TArrial != 0 && lmsg.TSent != 0 {
t1 := time.Unix(0, lmsg.TArrial)
if lmsg.TArrival != 0 && lmsg.TSent != 0 {
t1 := time.Unix(0, lmsg.TArrival)
t2 := time.Unix(0, lmsg.TSent)
offset := t0.Sub(t1) + t3.Sub(t2)
offset /= 2