[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet-go] branch master updated: Fixed issues from 'gnune
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet-go] branch master updated: Fixed issues from 'gnunet-developers' feedback: |
Date: |
Fri, 20 Sep 2019 10:10:33 +0200 |
This is an automated email from the git hooks/post-receive script.
bernd-fix pushed a commit to branch master
in repository gnunet-go.
The following commit(s) were added to refs/heads/master by this push:
new 170ce0e Fixed issues from 'gnunet-developers' feedback:
170ce0e is described below
commit 170ce0e4edadb079ad9ab98da23e4fda65c21851
Author: Bernd Fix <address@hidden>
AuthorDate: Fri Sep 20 10:06:39 2019 +0200
Fixed issues from 'gnunet-developers' feedback:
* correctly handle expiration time ("never")
* removed busy loop from service implementation ("CPU load")
---
src/gnunet/service/gns/gns.go | 5 ++---
src/gnunet/service/service.go | 6 +++++-
src/gnunet/util/format.go | 4 ++++
src/gnunet/util/time.go | 9 +++++++++
4 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/src/gnunet/service/gns/gns.go b/src/gnunet/service/gns/gns.go
index 9ac8b37..fb93c4b 100644
--- a/src/gnunet/service/gns/gns.go
+++ b/src/gnunet/service/gns/gns.go
@@ -3,7 +3,6 @@ package gns
import (
"encoding/hex"
"io"
- "time"
"github.com/bfix/gospel/crypto/ed25519"
"github.com/bfix/gospel/data"
@@ -179,7 +178,7 @@ func (s *GNSService) LookupNamecache(query
*crypto.HashCode, zoneKey *ed25519.Pu
break
}
// check if record has expired
- if m.Expire > 0 && int64(m.Expire) < time.Now().Unix() {
+ if util.Expired(m.Expire) {
logger.Printf(logger.ERROR, "[gns] block expired at
%s\n", util.Timestamp(m.Expire))
break
}
@@ -246,7 +245,7 @@ func (s *GNSService) LookupDHT(query *crypto.HashCode,
zoneKey *ed25519.PublicKe
break
}
// check if record has expired
- if m.Expire > 0 && int64(m.Expire) < time.Now().Unix() {
+ if util.Expired(m.Expire) {
logger.Printf(logger.ERROR, "[gns] block expired at
%s\n", util.Timestamp(m.Expire))
break
}
diff --git a/src/gnunet/service/service.go b/src/gnunet/service/service.go
index f43c385..5b44d47 100644
--- a/src/gnunet/service/service.go
+++ b/src/gnunet/service/service.go
@@ -21,6 +21,7 @@ type Service interface {
type ServiceImpl struct {
impl Service
hdlr chan transport.Channel
+ ctrl chan bool
srvc transport.ChannelServer
name string
running bool
@@ -31,6 +32,7 @@ func NewServiceImpl(name string, srv Service) *ServiceImpl {
return &ServiceImpl{
impl: srv,
hdlr: make(chan transport.Channel),
+ ctrl: make(chan bool),
srvc: nil,
name: name,
running: false,
@@ -67,7 +69,8 @@ func (si *ServiceImpl) Start(spec string) (err error) {
logger.Printf(logger.DBG, "[%s] Client
connected.\n", si.name)
go
si.impl.ServeClient(transport.NewMsgChannel(ch))
}
- default:
+ case <-si.ctrl:
+ break loop
}
}
logger.Printf(logger.DBG, "[%s] Service closing.\n", si.name)
@@ -85,6 +88,7 @@ func (si *ServiceImpl) Stop() error {
return fmt.Errorf("service not running")
}
si.running = false
+ si.ctrl <- true
logger.Printf(logger.DBG, "[%s] Service terminating.\n", si.name)
return si.impl.Stop()
diff --git a/src/gnunet/util/format.go b/src/gnunet/util/format.go
index b52418f..4d42520 100644
--- a/src/gnunet/util/format.go
+++ b/src/gnunet/util/format.go
@@ -3,6 +3,7 @@ package util
import (
"encoding/hex"
"fmt"
+ "math"
"net"
"time"
)
@@ -17,6 +18,9 @@ func AddressString(transport string, addr []byte) string {
}
func Timestamp(ts uint64) string {
+ if ts == math.MaxUint64 {
+ return "Never"
+ }
t := time.Unix(int64(ts/(1000*1000)), int64((ts%1000)*1000))
return t.Format(time.RFC3339Nano)
}
diff --git a/src/gnunet/util/time.go b/src/gnunet/util/time.go
index 89109a7..78b0722 100644
--- a/src/gnunet/util/time.go
+++ b/src/gnunet/util/time.go
@@ -1,6 +1,7 @@
package util
import (
+ "math"
"time"
)
@@ -12,6 +13,14 @@ func GetAbsoluteTimeOffset(t time.Duration) uint64 {
return getTimestamp(time.Now().Add(t))
}
+func Expired(ts uint64) bool {
+ // check for "never"
+ if ts == math.MaxUint64 {
+ return false
+ }
+ return ts < uint64(time.Now().Unix())
+}
+
func getTimestamp(t time.Time) uint64 {
secs := t.Unix()
usecs := t.Nanosecond() / 1000
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [gnunet-go] branch master updated: Fixed issues from 'gnunet-developers' feedback:,
gnunet <=