added host address accessors that return all, and l0k18 timelog

https://gtimelog.org/ the timelogging app. each entry after first on a day is "start" and entries with ** or ** are marked as slacking or otherwise, work, referring to the period prior until the previous entry.
This commit is contained in:
l0k18
2023-07-13 10:23:28 +01:00
parent 61f010bb6e
commit 6da7419e9a
7 changed files with 47 additions and 23 deletions

View File

@@ -52,7 +52,7 @@ func TestDispatcher(t *testing.T) {
if err != nil {
t.FailNow()
}
l2, e = transport.NewListener([]string{transport.GetHostAddress(l1.Host)},
l2, e = transport.NewListener([]string{transport.GetHostFirstMultiaddr(l1.Host)},
[]string{transport.LocalhostZeroIPv4TCP}, dataPath, k2, ctx,
transport.DefaultMTU)
if fails(e) {
@@ -63,7 +63,7 @@ func TestDispatcher(t *testing.T) {
msg1, _, e = tests.GenMessage(8192, "REQUEST")
msg2, _, e = tests.GenMessage(4096, "RESPONSE")
_, _ = msg1, msg2
hn1 := transport.GetHostAddress(l2.Host)
hn1 := transport.GetHostFirstMultiaddr(l2.Host)
// hn2 := transport.GetHostAddress(l1.Host)
var ks *crypto.KeySet
_, ks, e = crypto.NewSigner()

View File

@@ -2,7 +2,6 @@ package engine
import (
"context"
"errors"
"github.com/indra-labs/indra/pkg/crypto"
"github.com/indra-labs/indra/pkg/engine/node"
"github.com/indra-labs/indra/pkg/engine/transport"
@@ -13,14 +12,13 @@ import (
)
// CreateMockEngine creates an indra Engine with a random localhost listener.
func CreateMockEngine(seed, dataPath string) (ng *Engine, cancel func(), e error) {
func CreateMockEngine(seed, dataPath string, ctx context.Context) (ng *Engine) {
var e error
defer func(f *error) {
if *f != nil {
fails(os.RemoveAll(dataPath))
}
}(&e)
var ctx context.Context
ctx, cancel = context.WithCancel(context.Background())
var keys []*crypto.Keys
var k *crypto.Keys
if k, e = crypto.GenerateKeys(); fails(e) {
@@ -34,10 +32,9 @@ func CreateMockEngine(seed, dataPath string) (ng *Engine, cancel func(), e error
return
}
if l == nil {
cancel()
return nil, nil, errors.New("got nil listener")
panic("maybe you have no network device?")
}
sa := transport.GetHostAddress(l.Host)
sa := transport.GetHostFirstMultiaddr(l.Host)
var ap netip.AddrPort
var ma multiaddr.Multiaddr
if ma, e = multiaddr.NewMultiaddr(sa); fails(e) {
@@ -60,7 +57,8 @@ func CreateMockEngine(seed, dataPath string) (ng *Engine, cancel func(), e error
return
}
func CreateAndStartMockEngines(n int) (engines []*Engine, cleanup func(), e error) {
func CreateAndStartMockEngines(n, sessions int, ctx context.Context) (engines []*Engine, cleanup func(), e error) {
cleanup = func() {}
var seed string
dataPath := make([]string, n)
@@ -70,12 +68,12 @@ func CreateAndStartMockEngines(n int) (engines []*Engine, cleanup func(), e erro
return
}
var eng *Engine
if eng, _, e = CreateMockEngine(seed, dataPath[i]); fails(e) {
if eng = CreateMockEngine(seed, dataPath[i], ctx); fails(e) {
return
}
engines = append(engines, eng)
if i == 0 {
seed = transport.GetHostAddress(eng.Listener.Host)
seed = transport.GetHostFirstMultiaddr(eng.Listener.Host)
}
go eng.Start()
}
@@ -90,6 +88,9 @@ func CreateAndStartMockEngines(n int) (engines []*Engine, cleanup func(), e erro
fails(os.RemoveAll(dataPath[i]))
}
}
}
if sessions > 0 {
}
return
}

View File

@@ -1,6 +1,7 @@
package engine
import (
"context"
"github.com/indra-labs/indra"
"github.com/indra-labs/indra/pkg/codec/ad/addresses"
"github.com/indra-labs/indra/pkg/codec/ad/intro"
@@ -27,7 +28,8 @@ func TestEngine_PeerStore(t *testing.T) {
var e error
var engines []*Engine
var cleanup func()
engines, cleanup, e = CreateAndStartMockEngines(nTotal)
ctx, _ := context.WithCancel(context.Background())
engines, cleanup, e = CreateAndStartMockEngines(nTotal, 0, ctx)
adz := engines[0].Listener.Host.Addrs()
addrs := make([]*netip.AddrPort, len(adz))
for i := range adz {

View File

@@ -45,7 +45,7 @@ func NewDHT(ctx context.Context, host host.Host,
}
log.T.F(
"%s: Connection established with bootstrap node: %s",
blue(GetHostOnlyAddress(host)),
blue(GetHostOnlyFirstMultiaddr(host)),
blue((*peerinfo).Addrs[0]))
wg.Done()
}()

View File

@@ -183,20 +183,40 @@ type (
}
)
// GetHostAddress returns the multiaddr string encoding of a host.Host's network listener.
func GetHostAddress(ha host.Host) string {
// GetHostFirstMultiaddr returns the multiaddr string encoding of a host.Host's network listener.
func GetHostFirstMultiaddr(ha host.Host) string {
hostAddr, _ := multiaddr.NewMultiaddr(fmt.Sprintf("/p2p/%s",
ha.ID().String()))
addr := ha.Addrs()[0]
return addr.Encapsulate(hostAddr).String()
}
// GetHostOnlyAddress returns the multiaddr string without the p2p key.
func GetHostOnlyAddress(ha host.Host) string {
// GetHostOnlyFirstMultiaddr returns the multiaddr string without the p2p key.
func GetHostOnlyFirstMultiaddr(ha host.Host) string {
addr := ha.Addrs()[0]
return addr.String()
}
// GetHostMultiaddrs returns the multiaddr strings encoding of a host.Host's network listener.
//
// This includes (the repeated) p2p key sections of the peer identity key.
func GetHostMultiaddrs(ha host.Host) (addrs []string) {
hostAddr, _ := multiaddr.NewMultiaddr(fmt.Sprintf("/p2p/%s",
ha.ID().String()))
for _, v := range ha.Addrs() {
addrs = append(addrs, v.Encapsulate(hostAddr).String())
}
return
}
// GetHostOnlyMultiaddrs returns the multiaddr string without the p2p key.
func GetHostOnlyMultiaddrs(ha host.Host) (addrs []string) {
for _, v := range ha.Addrs() {
addrs = append(addrs, v.String())
}
return
}
func (l *Listener) ProtocolsAvailable() (p protocols.NetworkProtocols) {
if l == nil || l.Host == nil {
return protocols.IP4 | protocols.IP6
@@ -265,7 +285,7 @@ func (l *Listener) Dial(multiAddr string) (d *Conn) {
l.Lock()
l.connections[multiAddr] = d
l.Unlock()
hostAddress := GetHostOnlyAddress(d.Host)
hostAddress := GetHostOnlyFirstMultiaddr(d.Host)
go func() {
var e error
for {
@@ -343,7 +363,7 @@ func (l *Listener) handle(s network.Stream) {
if n, e = s.Read(b); fails(e) {
return
}
log.T.S(blue(GetHostOnlyAddress(l.
log.T.S(blue(GetHostOnlyFirstMultiaddr(l.
Host)) + " read " + fmt.Sprint(n) + " bytes from listener",
// b[:n].ToBytes(),
)

View File

@@ -38,7 +38,7 @@ func TestNewListener(t *testing.T) {
if err != nil {
t.FailNow()
}
l2, e = NewListener([]string{GetHostAddress(l1.Host)},
l2, e = NewListener([]string{GetHostFirstMultiaddr(l1.Host)},
[]string{LocalhostZeroIPv4TCP}, dataPath, k2, ctx, DefaultMTU)
if fails(e) {
t.FailNow()
@@ -47,8 +47,8 @@ func TestNewListener(t *testing.T) {
_ = msg2
msg1, _, e = tests.GenMessage(32, "REQUEST")
msg2, _, e = tests.GenMessage(32, "RESPONSE")
hn1 := GetHostAddress(l2.Host)
hn2 := GetHostAddress(l1.Host)
hn1 := GetHostFirstMultiaddr(l2.Host)
hn2 := GetHostFirstMultiaddr(l1.Host)
d1 := l1.Dial(hn1)
d2 := l2.Dial(hn2)
c1, c2 := l1.GetConnRecv(hn1), l2.GetConnRecv(hn2)

1
timelog/l0k18 Symbolic link
View File

@@ -0,0 +1 @@
/home/loki/.local/share/gtimelog/timelog.txt