File: transport_nonce_tcp.go

package info (click to toggle)
golang-dbus 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, bookworm-proposed-updates, forky, sid, trixie
  • size: 592 kB
  • sloc: makefile: 2
file content (39 lines) | stat: -rw-r--r-- 784 bytes parent folder | download | duplicates (5)
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
//+build !windows

package dbus

import (
	"errors"
	"io/ioutil"
	"net"
)

func init() {
	transports["nonce-tcp"] = newNonceTcpTransport
}

func newNonceTcpTransport(keys string) (transport, error) {
	host := getKey(keys, "host")
	port := getKey(keys, "port")
	noncefile := getKey(keys, "noncefile")
	if host == "" || port == "" || noncefile == "" {
		return nil, errors.New("dbus: unsupported address (must set host, port and noncefile)")
	}
	protocol, err := tcpFamily(keys)
	if err != nil {
		return nil, err
	}
	socket, err := net.Dial(protocol, net.JoinHostPort(host, port))
	if err != nil {
		return nil, err
	}
	b, err := ioutil.ReadFile(noncefile)
	if err != nil {
		return nil, err
	}
	_, err = socket.Write(b)
	if err != nil {
		return nil, err
	}
	return NewConn(socket)
}