// Publish publishes an announcement at an interval func (b *Beacon) Publish(announcement string, interval int) error { cmd := C.CString("PUBLISH") defer C.free(unsafe.Pointer(cmd)) cAnnouncement := C.CString(announcement) defer C.free(unsafe.Pointer(cAnnouncement)) cInterval := C.CString(strconv.Itoa(interval)) defer C.free(unsafe.Pointer(cInterval)) rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), cmd) if rc == -1 { return ErrActorCmd } rc = C.zstr_sendm(unsafe.Pointer(b.zactorT), cAnnouncement) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(b.zactorT), cInterval) if rc == -1 { return ErrActorCmd } return nil }
// Publish announces a key / value pair func (g *Gossip) Publish(key, value string) error { cmd := C.CString("PUBLISH") defer C.free(unsafe.Pointer(cmd)) cKey := C.CString(key) defer C.free(unsafe.Pointer(cKey)) cValue := C.CString(value) defer C.free(unsafe.Pointer(cValue)) rc := C.zstr_sendm(unsafe.Pointer(g.zactorT), cmd) if rc == -1 { return ErrActorCmd } rc = C.zstr_sendm(unsafe.Pointer(g.zactorT), cKey) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(g.zactorT), cValue) if rc == -1 { return ErrActorCmd } return nil }
// SetBackend accepts a socket type and endpoint, and sends a message // to the zactor thread telling it to set up a socket bound to the endpoint. func (p *Proxy) SetBackend(sockType int, endpoint string) error { typeString := getStringType(sockType) rc := C.zstr_sendm(unsafe.Pointer(p.zactorT), C.CString("BACKEND")) if rc == -1 { return ErrActorCmd } rc = C.zstr_sendm(unsafe.Pointer(p.zactorT), C.CString(typeString)) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(p.zactorT), C.CString(endpoint)) if rc == -1 { return ErrActorCmd } rc = C.zsock_wait(unsafe.Pointer(p.zactorT)) if rc == -1 { return ErrActorCmd } return nil }
// SetBackend accepts a socket type and endpoint, and sends a message // to the zactor thread telling it to set up a socket bound to the endpoint. func (p *Proxy) SetBackend(sockType int, endpoint string) error { typeString := getStringType(sockType) cmd := C.CString("BACKEND") defer C.free(unsafe.Pointer(cmd)) cTypeString := C.CString(typeString) defer C.free(unsafe.Pointer(cTypeString)) cEndpoint := C.CString(endpoint) defer C.free(unsafe.Pointer(cEndpoint)) rc := C.zstr_sendm(unsafe.Pointer(p.zactorT), cmd) if rc == -1 { return ErrActorCmd } rc = C.zstr_sendm(unsafe.Pointer(p.zactorT), cTypeString) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(p.zactorT), cEndpoint) if rc == -1 { return ErrActorCmd } rc = C.zsock_wait(unsafe.Pointer(p.zactorT)) if rc == -1 { return ErrActorCmd } return nil }
// Publish publishes an announcement at an interval func (b *Beacon) Publish(announcement string, interval int) error { rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), C.CString("PUBLISH")) if rc == -1 { return ErrActorCmd } rc = C.zstr_sendm(unsafe.Pointer(b.zactorT), C.CString(announcement)) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(b.zactorT), C.CString(strconv.Itoa(interval))) if rc == -1 { return ErrActorCmd } return nil }
// Subscribe subscribes to beacons matching the filter func (b *Beacon) Subscribe(filter string) error { rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), C.CString("SUBSCRIBE")) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(b.zactorT), C.CString(filter)) if rc == -1 { return ErrActorCmd } return nil }
// SetCapture accepts a socket endpoint and sets up a Push socket bound // to that endpoint, that sends a copy of all messages passing through // the proxy. func (p *Proxy) SetCapture(endpoint string) error { rc := C.zstr_sendm(unsafe.Pointer(p.zactorT), C.CString("CAPTURE")) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(p.zactorT), C.CString(endpoint)) if rc == -1 { return ErrActorCmd } return nil }
// Configure accepts a port number and configures // the beacon, returning an address func (b *Beacon) Configure(port int) (string, error) { rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), C.CString("CONFIGURE")) if rc == -1 { return "", ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(b.zactorT), C.CString(strconv.Itoa(port))) if rc == -1 { return "", ErrActorCmd } Chostname := C.zstr_recv(unsafe.Pointer(b.zactorT)) hostname := C.GoString(Chostname) return hostname, nil }
// Subscribe subscribes to beacons matching the filter func (b *Beacon) Subscribe(filter string) error { cmd := C.CString("SUBSCRIBE") defer C.free(unsafe.Pointer(cmd)) cFilter := C.CString(filter) defer C.free(unsafe.Pointer(cFilter)) rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), cmd) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(b.zactorT), cFilter) if rc == -1 { return ErrActorCmd } return nil }
// Connect connects the gossip service to a specified endpoint func (g *Gossip) Connect(endpoint string) error { cmd := C.CString("CONNECT") defer C.free(unsafe.Pointer(cmd)) cEndpoint := C.CString(endpoint) defer C.free(unsafe.Pointer(cEndpoint)) rc := C.zstr_sendm(unsafe.Pointer(g.zactorT), cmd) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(g.zactorT), cEndpoint) if rc == -1 { return ErrActorCmd } return nil }
// SetCapture accepts a socket endpoint and sets up a Push socket bound // to that endpoint, that sends a copy of all messages passing through // the proxy. func (p *Proxy) SetCapture(endpoint string) error { cmd := C.CString("CAPTURE") defer C.free(unsafe.Pointer(cmd)) cEndpoint := C.CString(endpoint) defer C.free(unsafe.Pointer(cEndpoint)) rc := C.zstr_sendm(unsafe.Pointer(p.zactorT), cmd) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(p.zactorT), cEndpoint) if rc == -1 { return ErrActorCmd } return nil }
// Curve sets auth method to curve func (a *Auth) Curve(allowed string) error { cmd := C.CString("CURVE") defer C.free(unsafe.Pointer(cmd)) cAllowed := C.CString(allowed) defer C.free(unsafe.Pointer(cAllowed)) rc := C.zstr_sendm(unsafe.Pointer(a.zactorT), cmd) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(a.zactorT), cAllowed) if rc == -1 { return ErrActorCmd } C.zsock_wait(unsafe.Pointer(a.zactorT)) return nil }
// Allow removes a previous Deny func (a *Auth) Allow(address string) error { cmd := C.CString("ALLOW") defer C.free(unsafe.Pointer(cmd)) cAddress := C.CString(address) defer C.free(unsafe.Pointer(cAddress)) rc := C.zstr_sendm(unsafe.Pointer(a.zactorT), cmd) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(a.zactorT), cAddress) if rc == -1 { return ErrActorCmd } C.zsock_wait(unsafe.Pointer(a.zactorT)) return nil }
// Plain sets auth method to plain func (a *Auth) Plain(directory string) error { cmd := C.CString("PLAIN") defer C.free(unsafe.Pointer(cmd)) cDirectory := C.CString(directory) defer C.free(unsafe.Pointer(cDirectory)) rc := C.zstr_sendm(unsafe.Pointer(a.zactorT), cmd) if rc == -1 { return ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(a.zactorT), cDirectory) if rc == -1 { return ErrActorCmd } C.zsock_wait(unsafe.Pointer(a.zactorT)) return nil }
// Configure accepts a port number and configures // the beacon, returning an address func (b *Beacon) Configure(port int) (string, error) { cmd := C.CString("CONFIGURE") defer C.free(unsafe.Pointer(cmd)) cPort := C.CString(strconv.Itoa(port)) defer C.free(unsafe.Pointer(cPort)) rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), cmd) if rc == -1 { return "", ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(b.zactorT), cPort) if rc == -1 { return "", ErrActorCmd } cHostname := C.zstr_recv(unsafe.Pointer(b.zactorT)) hostname := C.GoString(cHostname) return hostname, nil }