mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-19 16:56:39 +00:00
Compare commits
3 Commits
trigger-pr
...
fix/up-seq
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55d8b4e42c | ||
|
|
9b8f7d75b3 | ||
|
|
57f3af57f4 |
@@ -231,7 +231,7 @@ func FlagNameToEnvVar(cmdFlag string, prefix string) string {
|
|||||||
|
|
||||||
// DialClientGRPCServer returns client connection to the daemon server.
|
// DialClientGRPCServer returns client connection to the daemon server.
|
||||||
func DialClientGRPCServer(ctx context.Context, addr string) (*grpc.ClientConn, error) {
|
func DialClientGRPCServer(ctx context.Context, addr string) (*grpc.ClientConn, error) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
|
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
return grpc.DialContext(
|
return grpc.DialContext(
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ func runInDaemonMode(ctx context.Context, cmd *cobra.Command, pm *profilemanager
|
|||||||
|
|
||||||
client := proto.NewDaemonServiceClient(conn)
|
client := proto.NewDaemonServiceClient(conn)
|
||||||
|
|
||||||
status, err := client.Status(ctx, &proto.StatusRequest{})
|
status, err := client.Status(ctx, &proto.StatusRequest{WaitForConnectingShift: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get daemon status: %v", err)
|
return fmt.Errorf("unable to get daemon status: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.6
|
// protoc-gen-go v1.36.6
|
||||||
// protoc v5.29.3
|
// protoc v3.21.9
|
||||||
// source: daemon.proto
|
// source: daemon.proto
|
||||||
|
|
||||||
package proto
|
package proto
|
||||||
@@ -794,6 +794,7 @@ type StatusRequest struct {
|
|||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
GetFullPeerStatus bool `protobuf:"varint,1,opt,name=getFullPeerStatus,proto3" json:"getFullPeerStatus,omitempty"`
|
GetFullPeerStatus bool `protobuf:"varint,1,opt,name=getFullPeerStatus,proto3" json:"getFullPeerStatus,omitempty"`
|
||||||
ShouldRunProbes bool `protobuf:"varint,2,opt,name=shouldRunProbes,proto3" json:"shouldRunProbes,omitempty"`
|
ShouldRunProbes bool `protobuf:"varint,2,opt,name=shouldRunProbes,proto3" json:"shouldRunProbes,omitempty"`
|
||||||
|
WaitForConnectingShift bool `protobuf:"varint,3,opt,name=waitForConnectingShift,proto3" json:"waitForConnectingShift,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@@ -842,6 +843,13 @@ func (x *StatusRequest) GetShouldRunProbes() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *StatusRequest) GetWaitForConnectingShift() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.WaitForConnectingShift
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
type StatusResponse struct {
|
type StatusResponse struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
// status of the server.
|
// status of the server.
|
||||||
@@ -4673,10 +4681,11 @@ const file_daemon_proto_rawDesc = "" +
|
|||||||
"\f_profileNameB\v\n" +
|
"\f_profileNameB\v\n" +
|
||||||
"\t_username\"\f\n" +
|
"\t_username\"\f\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"UpResponse\"g\n" +
|
"UpResponse\"\x9f\x01\n" +
|
||||||
"\rStatusRequest\x12,\n" +
|
"\rStatusRequest\x12,\n" +
|
||||||
"\x11getFullPeerStatus\x18\x01 \x01(\bR\x11getFullPeerStatus\x12(\n" +
|
"\x11getFullPeerStatus\x18\x01 \x01(\bR\x11getFullPeerStatus\x12(\n" +
|
||||||
"\x0fshouldRunProbes\x18\x02 \x01(\bR\x0fshouldRunProbes\"\x82\x01\n" +
|
"\x0fshouldRunProbes\x18\x02 \x01(\bR\x0fshouldRunProbes\x126\n" +
|
||||||
|
"\x16waitForConnectingShift\x18\x03 \x01(\bR\x16waitForConnectingShift\"\x82\x01\n" +
|
||||||
"\x0eStatusResponse\x12\x16\n" +
|
"\x0eStatusResponse\x12\x16\n" +
|
||||||
"\x06status\x18\x01 \x01(\tR\x06status\x122\n" +
|
"\x06status\x18\x01 \x01(\tR\x06status\x122\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ message UpResponse {}
|
|||||||
message StatusRequest{
|
message StatusRequest{
|
||||||
bool getFullPeerStatus = 1;
|
bool getFullPeerStatus = 1;
|
||||||
bool shouldRunProbes = 2;
|
bool shouldRunProbes = 2;
|
||||||
|
bool waitForConnectingShift = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message StatusResponse{
|
message StatusResponse{
|
||||||
|
|||||||
@@ -119,14 +119,12 @@ func (s *Server) Start() error {
|
|||||||
// if current state contains any error, return it
|
// if current state contains any error, return it
|
||||||
// in all other cases we can continue execution only if status is idle and up command was
|
// in all other cases we can continue execution only if status is idle and up command was
|
||||||
// not in the progress or already successfully established connection.
|
// not in the progress or already successfully established connection.
|
||||||
status, err := state.Status()
|
_, err := state.Status()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if status != internal.StatusIdle {
|
state.Set(internal.StatusConnecting)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(s.rootCtx)
|
ctx, cancel := context.WithCancel(s.rootCtx)
|
||||||
s.actCancel = cancel
|
s.actCancel = cancel
|
||||||
@@ -961,6 +959,33 @@ func (s *Server) sendLogoutRequestWithConfig(ctx context.Context, config *profil
|
|||||||
return mgmClient.Logout()
|
return mgmClient.Logout()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func waitStateShift(ctx context.Context) {
|
||||||
|
timer := time.NewTimer(5 * time.Second)
|
||||||
|
defer timer.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
log.Warnf("context done while waiting for state shift: %v", ctx.Err())
|
||||||
|
timer.Stop()
|
||||||
|
return
|
||||||
|
case <-timer.C:
|
||||||
|
log.Warnf("state shift timed out")
|
||||||
|
timer.Stop()
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
status, err := internal.CtxGetState(ctx).Status()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("failed to get status: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if status != internal.StatusConnecting {
|
||||||
|
log.Infof("state shifting status: %v", status)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Status returns the daemon status
|
// Status returns the daemon status
|
||||||
func (s *Server) Status(
|
func (s *Server) Status(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
@@ -973,6 +998,10 @@ func (s *Server) Status(
|
|||||||
s.mutex.Lock()
|
s.mutex.Lock()
|
||||||
defer s.mutex.Unlock()
|
defer s.mutex.Unlock()
|
||||||
|
|
||||||
|
if msg.WaitForConnectingShift {
|
||||||
|
waitStateShift(s.rootCtx)
|
||||||
|
}
|
||||||
|
|
||||||
status, err := internal.CtxGetState(s.rootCtx).Status()
|
status, err := internal.CtxGetState(s.rootCtx).Status()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user