dial establishes a connection to our peer Seesaw node.
()
| 359 | |
| 360 | // dial establishes a connection to our peer Seesaw node. |
| 361 | func (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. |
| 391 | func (sc *syncClient) close() error { |