Documentation
¶
Overview ¶
Package crosscoap implements a proxy+translator server that listens for incoming CoAP requests, translates them to HTTP requests which are proxied to the backend, and translates the respones back to CoAP (if the CoAP client request was confirmable).
Example:
package main
import (
"log"
"net"
"os"
"time"
"github.com/ibm-security-innovation/crosscoap"
)
func main() {
timeout := time.Duration(10 * time.Second)
appLog := log.New(os.Stderr, "[example] ", log.LstdFlags)
udpAddr, err := net.ResolveUDPAddr("udp", "0.0.0.0:5683")
if err != nil {
appLog.Fatalln("Can't resolve UDP addr")
}
udpListener, err := net.ListenUDP("udp", udpAddr)
if err != nil {
errorLog.Fatalln("Can't listen on UDP")
}
defer udpListener.Close()
p := crosscoap.Proxy{
Listener: udpListener,
BackendURL: "http://127.0.0.1:8000/",
Timeout: &timeout,
AccessLog: appLog,
ErrorLog: appLog,
}
appLog.Fatal(p.Serve())
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
ListenAndServe listens for incoming CoAP requests on the given protocol and address and proxy them to the HTTP server backendURL.
Types ¶
type Proxy ¶
type Proxy struct {
// A UDP listener that will accept the incoming CoAP requests.
Listener *net.UDPConn
// URL of the HTTP (or HTTPS) backend server to which requests will be
// proxied.
BackendURL string
// Timeout for requests to the HTTP backend. If nil, a default of 5
// seconds is used.
Timeout *time.Duration
// AccessLog specifies an optional logger which records each incoming
// request received by the proxy. If nil, requests are not logged.
AccessLog *log.Logger
// ErrorLog specifies an optional logger for errors that occur when
// attempting to proxy the request. If nil, error logging goes to
// os.Stderr via the log package's standard logger.
ErrorLog *log.Logger
}
Proxy is CoAP server that takes an incoming CoAP request, translates it to an HTTP resquest and sends it to a backend HTTP server; the response it translated back to CoAP and returned to the original client.
Click to show internal directories.
Click to hide internal directories.