-
Notifications
You must be signed in to change notification settings - Fork 0
/
dial.go
37 lines (30 loc) · 925 Bytes
/
dial.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
package dqlite
import (
"context"
"net"
"github.com/openPanel/core/app/generated/pb"
"github.com/openPanel/core/app/global"
"github.com/openPanel/core/app/global/log"
"github.com/openPanel/core/app/tools/rpcDialer"
)
// DialFunction ctx used to control first connect timeout, just ignore
func DialFunction(_ context.Context, address string) (net.Conn, error) {
if address == global.App.NodeInfo.ServerId {
server, client := net.Pipe()
AcceptChan <- client
return server, nil
}
conn, err := rpcDialer.DialWithServerId(address)
if err != nil {
log.Debugf("dial dqlite err: %v", err)
return nil, err
}
client := pb.NewDqliteConnectionClient(conn)
stream, err := client.ServeDqlite(context.Background())
if err != nil {
log.Debugf("dial dqlite err: %v", err)
return nil, err
}
return NewClientRpcConn(stream, global.App.NodeInfo.ServerId, address), nil
}
var AcceptChan = make(chan net.Conn)