MCPcopy
hub / github.com/google/seesaw / dial

Method dial

engine/sync.go:361–388  ·  view source on GitHub ↗

dial establishes a connection to our peer Seesaw node.

()

Source from the content-addressed store, hash-verified

359
360// dial establishes a connection to our peer Seesaw node.
361func (sc *syncClient) dial() error {
362 sc.lock.Lock()
363 defer sc.lock.Unlock()
364 if sc.client != nil {
365 sc.refs++
366 return nil
367 }
368
369 // TODO(jsing): Make this default to IPv6, if configured.
370 peer := &net.TCPAddr{
371 IP: sc.engine.config.Peer.IPv4Addr,
372 Port: sc.engine.config.SyncPort,
373 }
374 self := &net.TCPAddr{
375 IP: sc.engine.config.Node.IPv4Addr,
376 }
377 d := net.Dialer{
378 Timeout: time.Second * 2,
379 LocalAddr: self,
380 }
381 conn, err := d.Dial("tcp", peer.String())
382 if err != nil {
383 return fmt.Errorf("failed to connect: %v", err)
384 }
385 sc.client = rpc.NewClient(conn)
386 sc.refs = 1
387 return nil
388}
389
390// close closes an existing connection to our peer Seesaw node.
391func (sc *syncClient) close() error {

Callers 2

failoverMethod · 0.95
runOnceMethod · 0.95

Calls 2

DialMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected