/
githubmirror
/
client
Обзор
Документация
Войти
/
githubmirror
/
client
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
go/service/reachability.go
114 строк
3 KB
chrisnojima
build(mobile): harden gobuild.sh and go bind pipeline 2 (#29364)
08 июл 2026, 15:25
Не верифицирован
08 июл 2026, 15:25
19b55b3
Код
Авторство
О чём код?
// Copyright 2015 Keybase, Inc. All rights reserved. Use of // this source code is governed by the included BSD license. package service import ( "context" "sync" "time" "github.com/keybase/client/go/libkb" "github.com/keybase/client/go/protocol/keybase1" "github.com/keybase/go-framed-msgpack-rpc/rpc" ) type reachabilityHandler struct { *BaseHandler libkb.Contextified service *Service } func newReachabilityHandler(xp rpc.Transporter, g *libkb.GlobalContext, service *Service) *reachabilityHandler { return &reachabilityHandler{ BaseHandler: NewBaseHandler(g, xp), Contextified: libkb.NewContextified(g), service: service, } } func (h *reachabilityHandler) ReachabilityChanged(_ context.Context, _ keybase1.Reachability) (err error) { h.G().Trace("ReachabilityChanged", &err)() return nil } func (h *reachabilityHandler) StartReachability(_ context.Context) (res keybase1.Reachability, err error) { h.G().Trace("StartReachability", &err)() return keybase1.Reachability{ Reachable: keybase1.Reachable_UNKNOWN, }, nil } func (h *reachabilityHandler) CheckReachability(ctx context.Context) (res keybase1.Reachability, err error) { h.G().Trace("CheckReachability", &err)() // reachability is wired up during startupGregor, which can lag behind the // first client connection (e.g. an online tryLogin blocking ahead of it on // mobile). Guard against a nil reachability so an early call returns UNKNOWN // instead of panicking. r := h.service.reachability if r == nil { return keybase1.Reachability{Reachable: keybase1.Reachable_UNKNOWN}, nil } return r.check(ctx), nil } type reachability struct { libkb.Contextified lastReachability keybase1.Reachability setMutex sync.Mutex gh *gregorHandler } func newReachability(g *libkb.GlobalContext, gh *gregorHandler) *reachability { return &reachability{ Contextified: libkb.NewContextified(g), gh: gh, } } func (h *reachability) setReachability(r keybase1.Reachability) { h.setMutex.Lock() changed := h.lastReachability.Reachable != r.Reachable h.lastReachability = r h.setMutex.Unlock() if changed { h.G().Log.Debug("Reachability changed: %#v", r) h.G().NotifyRouter.HandleReachability(r) } } func (h *reachability) check(ctx context.Context) (k keybase1.Reachability) { reachable := h.gh.isReachable(ctx) if reachable { k.Reachable = keybase1.Reachable_YES } else { k.Reachable = keybase1.Reachable_NO } h.setReachability(k) return k } func (h *reachability) ConnectedSince(ctx context.Context) time.Time { return h.gh.connectedSince() } func (h *reachability) IsConnected(ctx context.Context) libkb.ConnectivityMonitorResult { h.setMutex.Lock() defer h.setMutex.Unlock() switch h.lastReachability.Reachable { case keybase1.Reachable_YES: return libkb.ConnectivityMonitorYes case keybase1.Reachable_NO: return libkb.ConnectivityMonitorNo default: return libkb.ConnectivityMonitorUnknown } } func (h *reachability) CheckReachability(ctx context.Context) error { h.check(ctx) return nil }