Pass + Doc

This commit is contained in:
mr
2026-02-24 14:31:37 +01:00
parent 572da29fd4
commit 779e36aaef
40 changed files with 1875 additions and 353 deletions

View File

@@ -469,8 +469,18 @@ func SendHeartbeat(ctx context.Context, proto protocol.ID, name string, h host.H
}()
}
func TempStream(h host.Host, ad pp.AddrInfo, proto protocol.ID, did string, streams ProtocolStream, mu *sync.RWMutex) (ProtocolStream, error) {
if ctxTTL, err := context.WithTimeout(context.Background(), 2*time.Second); err == nil {
type ProtocolInfo struct {
PersistantStream bool
WaitResponse bool
TTL time.Duration
}
func TempStream(h host.Host, ad pp.AddrInfo, proto protocol.ID, did string, streams ProtocolStream, pts map[protocol.ID]*ProtocolInfo, mu *sync.RWMutex) (ProtocolStream, error) {
expiry := 2 * time.Second
if pts[proto] != nil {
expiry = pts[proto].TTL
}
if ctxTTL, err := context.WithTimeout(context.Background(), expiry); err == nil {
if h.Network().Connectedness(ad.ID) != network.Connected {
if err := h.Connect(ctxTTL, ad); err != nil {
return streams, err
@@ -484,7 +494,7 @@ func TempStream(h host.Host, ad pp.AddrInfo, proto protocol.ID, did string, stre
streams[proto] = map[pp.ID]*Stream{}
}
mu.Unlock()
time.AfterFunc(2*time.Second, func() {
time.AfterFunc(expiry, func() {
mu.Lock()
defer mu.Unlock()
delete(streams[proto], ad.ID)
@@ -492,7 +502,7 @@ func TempStream(h host.Host, ad pp.AddrInfo, proto protocol.ID, did string, stre
streams[ProtocolPublish][ad.ID] = &Stream{
DID: did,
Stream: s,
Expiry: time.Now().UTC().Add(2 * time.Second),
Expiry: time.Now().UTC().Add(expiry),
}
mu.Unlock()
return streams, nil