6
6
"crypto/x509"
7
7
"errors"
8
8
"fmt"
9
- "strings "
9
+ "net/url "
10
10
"sync"
11
11
"time"
12
12
@@ -31,9 +31,12 @@ type GRPCClient struct {
31
31
}
32
32
33
33
func NewClient (addr , payload , signature string , interval time.Duration ) (* GRPCClient , error ) {
34
+ parsedURL , err := url .Parse (addr )
35
+ if err != nil {
36
+ return nil , fmt .Errorf ("parsing url: %w" , err )
37
+ }
34
38
var opts []grpc.DialOption
35
-
36
- if strings .Contains (addr , "443" ) {
39
+ if parsedURL .Scheme == "https" {
37
40
certPool , err := x509 .SystemCertPool ()
38
41
if err != nil || certPool == nil {
39
42
log .Debugf ("System cert pool not available; falling back to embedded cert, error: %v" , err )
@@ -58,7 +61,7 @@ func NewClient(addr, payload, signature string, interval time.Duration) (*GRPCCl
58
61
grpc .WithDefaultServiceConfig (`{"healthCheckConfig": {"serviceName": ""}}` ),
59
62
)
60
63
61
- conn , err := grpc .NewClient (addr , opts ... )
64
+ conn , err := grpc .NewClient (fmt . Sprintf ( "%s:%s" , parsedURL . Hostname (), parsedURL . Port ()) , opts ... )
62
65
if err != nil {
63
66
return nil , fmt .Errorf ("creating new grpc client: %w" , err )
64
67
}
@@ -100,6 +103,11 @@ func (c *GRPCClient) establishStreamAndReceive(ctx context.Context, msgHandler f
100
103
return fmt .Errorf ("create event stream: %w" , err )
101
104
}
102
105
106
+ err = stream .Send (& proto.FlowEvent {IsInitiator : true })
107
+ if err != nil {
108
+ log .Infof ("failed to send initiator message to flow receiver but will attempt to continue. Error: %s" , err )
109
+ }
110
+
103
111
if err = checkHeader (stream ); err != nil {
104
112
return fmt .Errorf ("check header: %w" , err )
105
113
}
0 commit comments