-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
83 lines (65 loc) · 1.82 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-FileCopyrightText: 2025 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package wrpnng
import (
"context"
"fmt"
"net"
"github.com/xmidt-org/eventor"
"github.com/xmidt-org/wrp-go/v3"
"github.com/xmidt-org/wrpnng/internal/receiver"
"github.com/xmidt-org/wrpnng/internal/sender"
)
// Client is a WRP <-> nanomsg client. The client is responsible for sending
// messages to the network and receiving messages from the network. It also
// handles the registration message and sends heartbeats at regular intervals.
type Client struct {
clientURL string
serverURL string
rOpts []receiver.Option
r *receiver.Receiver
sOpts []sender.Option
s *sender.Sender
egress eventor.Eventor[wrp.Modifier]
}
// NewClient creates a new client. The client is not started until Start is
// called.
func NewClient(opts ...ClientOption) (*Client, error) {
var client Client
defaults := []ClientOption{}
vadors := []ClientOption{
determineClientURL(),
validateClient(),
}
opts = append(defaults, opts...)
opts = append(opts, vadors...)
for _, opt := range opts {
if opt != nil {
if err := opt.apply(&client); err != nil {
return nil, err
}
}
}
return &Client{}, nil
}
// Start starts the client. This call is idempotent.
func (c *Client) Start() error {
return nil
}
// Stop stops the client. This call is idempotent.
func (c *Client) Stop() error {
return nil
}
// ProcessWRP is called when a message should be sent to the network.
func (c *Client) ProcessWRP(ctx context.Context, msg wrp.Message) error {
return nil
}
func findOpenURL() (string, error) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return "", err
}
defer listener.Close()
addr := listener.Addr().(*net.TCPAddr)
return fmt.Sprintf("tcp://127.0.0.1:%d", addr.Port), nil
}