Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Server into Main. #717

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ build/
dist/
__pycache__/
.vscode/
*.pem
*.crt
*.csr
*.exe
.idea/
__debug*
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# go test -count=1 disables the test cache so that all tests are run every time.

all: test integration examples
all: test integration selfintegration examples

test:
go test -count=1 -race ./...
Expand All @@ -11,6 +11,9 @@ lint:
integration:
go test -count=1 -race -v -tags=integration ./uatest/...

selfintegration:
go test -count=1 -race -v -tags=integration ./uatest2/...

examples:
go build -o build/ ./examples/...

Expand All @@ -22,9 +25,9 @@ install-py-opcua:
pip3 install opcua

gen:
go install golang.org/x/tools/cmd/stringer@latest
which stringer || go install golang.org/x/tools/cmd/stringer@latest
find . -name '*_gen.go' -delete
go generate ./...
go mod tidy

release:
GITHUB_TOKEN=$$(security find-generic-password -gs GITHUB_TOKEN -w) goreleaser --clean
Expand Down
111 changes: 69 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ We would be happy if you can add your equipment to the list. Just open a PR :)
| B&R Automation PC 3100 | v0.3.x | production | ACS |
| InfluxDB Telegraf plugin | v0.3.x | ? | Community |

## Supported Features
## Supported Client Features

The current focus is on the OPC UA Binary protocol over TCP. No other protocols are supported at this point.

Expand All @@ -178,51 +178,78 @@ The current focus is on the OPC UA Binary protocol over TCP. No other protocols
| | User Name Password | Yes | |
| | X509 Certificate | Yes | |

## Supported Server Features

The current focus is on the OPC UA Binary protocol over TCP. No other protocols are supported at this point.

| Categories | Features | Supported | Notes |
|----------------|----------------------------------|-----------|-------------|
| Encoding | OPC UA Binary | Yes | |
| | OPC UA JSON | | not planned |
| | OPC UA XML | | not planned |
| Transport | UA-TCP UA-SC UA Binary | Yes | |
| | OPC UA HTTPS | | not planned |
| | SOAP-HTTP WS-SC UA Binary | | not planned |
| | SOAP-HTTP WS-SC UA XML | | not planned |
| | SOAP-HTTP WS-SC UA XML-UA Binary | | not planned |
| Encryption | None | Yes | |
| | Basic128Rsa15 | Untested | |
| | Basic256 | Untested | |
| | Basic256Sha256 | Untested | |
| Authentication | Anonymous | Yes | |
| | User Name Password | Untested | |
| | X509 Certificate | Untested | |


### Services

Here is the current set of supported services. For low-level access use the client `Send` function directly.

| Service Set | Service | Client | Notes |
|-----------------------------|-------------------------------|--------|--------------|
| Discovery Service Set | FindServers | Yes | |
| | FindServersOnNetwork | Yes | |
| | GetEndpoints | Yes | |
| | RegisterServer | | |
| | RegisterServer2 | | |
| Secure Channel Service Set | OpenSecureChannel | Yes | |
| | CloseSecureChannel | Yes | |
| Session Service Set | CreateSession | Yes | |
| | CloseSession | Yes | |
| | ActivateSession | Yes | |
| | Cancel | | |
| Node Management Service Set | AddNodes | | |
| | AddReferences | | |
| | DeleteNodes | | |
| | DeleteReferences | | |
| View Service Set | Browse | Yes | |
| | BrowseNext | Yes | |
| | TranslateBrowsePathsToNodeIds | | |
| | RegisterNodes | Yes | |
| | UnregisterNodes | Yes | |
| Query Service Set | QueryFirst | | |
| | QueryNext | | |
| Attribute Service Set | Read | Yes | |
| | Write | Yes | |
| | HistoryRead | Yes | |
| | HistoryUpdate | | |
| Method Service Set | Call | Yes | |
| MonitoredItems Service Set | CreateMonitoredItems | Yes | |
| | DeleteMonitoredItems | Yes | |
| | ModifyMonitoredItems | Yes | |
| | SetMonitoringMode | Yes | |
| | SetTriggering | | |
| Subscription Service Set | CreateSubscription | Yes | |
| | ModifySubscription | | |
| | SetPublishingMode | | |
| | Publish | Yes | |
| | Republish | | |
| | DeleteSubscriptions | Yes | |
| | TransferSubscriptions | | |

| Service Set | Service | Client | Server | Notes |
|-----------------------------|-------------------------------|--------|--------|--------------|
| Discovery Service Set | FindServers | Yes | | |
| | FindServersOnNetwork | Yes | | |
| | GetEndpoints | Yes | | |
| | RegisterServer | | | |
| | RegisterServer2 | | | |
| Secure Channel Service Set | OpenSecureChannel | Yes | Yes* | |
| | CloseSecureChannel | Yes | Yes* | |
| Session Service Set | CreateSession | Yes | Yes | |
| | CloseSession | Yes | Yes | |
| | ActivateSession | Yes | Yes | |
| | Cancel | | | |
| Node Management Service Set | AddNodes | | | |
| | AddReferences | | | |
| | DeleteNodes | | | |
| | DeleteReferences | | | |
| View Service Set | Browse | Yes | Yes | |
| | BrowseNext | Yes | | |
| | TranslateBrowsePathsToNodeIds | | | |
| | RegisterNodes | Yes | | |
| | UnregisterNodes | Yes | | |
| Query Service Set | QueryFirst | | | |
| | QueryNext | | | |
| Attribute Service Set | Read | Yes | Yes | |
| | Write | Yes | Yes | |
| | HistoryRead | Yes | | |
| | HistoryUpdate | | | |
| Method Service Set | Call | Yes | | |
| MonitoredItems Service Set | CreateMonitoredItems | Yes | Yes | |
| | DeleteMonitoredItems | Yes | Yes | |
| | ModifyMonitoredItems | Yes | Yes | |
| | SetMonitoringMode | Yes | Yes | |
| | SetTriggering | | | |
| Subscription Service Set | CreateSubscription | Yes | Yes | |
| | ModifySubscription | | | |
| | SetPublishingMode | | | |
| | Publish | Yes | Yes | |
| | Republish | | | |
| | DeleteSubscriptions | Yes | Yes | |
| | TransferSubscriptions | | | |

* not all encryption schemes are fully functional at this time


## Authors

Expand Down
38 changes: 19 additions & 19 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ func (c *Client) CreateSession(ctx context.Context, cfg *uasc.SessionConfig) (*S
var s *Session
// for the CreateSessionRequest the authToken is always nil.
// use c.SecureChannel().SendRequest() to enforce this.
err := c.SecureChannel().SendRequest(ctx, req, nil, func(v interface{}) error {
err := c.SecureChannel().SendRequest(ctx, req, nil, func(v ua.Response) error {
var res *ua.CreateSessionResponse
if err := safeAssign(v, &res); err != nil {
return err
Expand Down Expand Up @@ -876,7 +876,7 @@ func (c *Client) ActivateSession(ctx context.Context, s *Session) error {
UserIdentityToken: ua.NewExtensionObject(s.cfg.UserIdentityToken),
UserTokenSignature: s.cfg.UserTokenSignature,
}
return c.SecureChannel().SendRequest(ctx, req, s.resp.AuthenticationToken, func(v interface{}) error {
return c.SecureChannel().SendRequest(ctx, req, s.resp.AuthenticationToken, func(v ua.Response) error {
var res *ua.ActivateSessionResponse
if err := safeAssign(v, &res); err != nil {
return err
Expand Down Expand Up @@ -918,7 +918,7 @@ func (c *Client) closeSession(ctx context.Context, s *Session) error {
}
req := &ua.CloseSessionRequest{DeleteSubscriptions: true}
var res *ua.CloseSessionResponse
return c.Send(ctx, req, func(v interface{}) error {
return c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
}
Expand All @@ -936,7 +936,7 @@ func (c *Client) DetachSession(ctx context.Context) (*Session, error) {
// Send sends the request via the secure channel and registers a handler for
// the response. If the client has an active session it injects the
// authentication token.
func (c *Client) Send(ctx context.Context, req ua.Request, h func(interface{}) error) error {
func (c *Client) Send(ctx context.Context, req ua.Request, h func(ua.Response) error) error {
stats.Client().Add("Send", 1)

err := c.sendWithTimeout(ctx, req, c.cfg.sechan.RequestTimeout, h)
Expand All @@ -948,7 +948,7 @@ func (c *Client) Send(ctx context.Context, req ua.Request, h func(interface{}) e
// sendWithTimeout sends the request via the secure channel with a custom timeout and registers a handler for
// the response. If the client has an active session it injects the
// authentication token.
func (c *Client) sendWithTimeout(ctx context.Context, req ua.Request, timeout time.Duration, h func(interface{}) error) error {
func (c *Client) sendWithTimeout(ctx context.Context, req ua.Request, timeout time.Duration, h uasc.ResponseHandler) error {
sc := c.SecureChannel()
if sc == nil {
return ua.StatusBadServerNotConnected
Expand Down Expand Up @@ -981,7 +981,7 @@ func (c *Client) FindServers(ctx context.Context) (*ua.FindServersResponse, erro
EndpointURL: c.endpointURL,
}
var res *ua.FindServersResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand All @@ -993,7 +993,7 @@ func (c *Client) FindServersOnNetwork(ctx context.Context) (*ua.FindServersOnNet

req := &ua.FindServersOnNetworkRequest{}
var res *ua.FindServersOnNetworkResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand All @@ -1007,7 +1007,7 @@ func (c *Client) GetEndpoints(ctx context.Context) (*ua.GetEndpointsResponse, er
EndpointURL: c.endpointURL,
}
var res *ua.GetEndpointsResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand Down Expand Up @@ -1046,7 +1046,7 @@ func (c *Client) Read(ctx context.Context, req *ua.ReadRequest) (*ua.ReadRespons
req = cloneReadRequest(req)

var res *ua.ReadResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
err := safeAssign(v, &res)
if err != nil {
return err
Expand Down Expand Up @@ -1077,7 +1077,7 @@ func (c *Client) Write(ctx context.Context, req *ua.WriteRequest) (*ua.WriteResp
stats.Client().Add("NodesToWrite", int64(len(req.NodesToWrite)))

var res *ua.WriteResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand Down Expand Up @@ -1117,7 +1117,7 @@ func (c *Client) Browse(ctx context.Context, req *ua.BrowseRequest) (*ua.BrowseR
req = cloneBrowseRequest(req)

var res *ua.BrowseResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand All @@ -1131,7 +1131,7 @@ func (c *Client) Call(ctx context.Context, req *ua.CallMethodRequest) (*ua.CallM
MethodsToCall: []*ua.CallMethodRequest{req},
}
var res *ua.CallResponse
err := c.Send(ctx, creq, func(v interface{}) error {
err := c.Send(ctx, creq, func(v ua.Response) error {
return safeAssign(v, &res)
})
if err != nil {
Expand All @@ -1148,7 +1148,7 @@ func (c *Client) BrowseNext(ctx context.Context, req *ua.BrowseNextRequest) (*ua
stats.Client().Add("BrowseNext", 1)

var res *ua.BrowseNextResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand All @@ -1162,7 +1162,7 @@ func (c *Client) RegisterNodes(ctx context.Context, req *ua.RegisterNodesRequest
stats.Client().Add("NodesToRegister", int64(len(req.NodesToRegister)))

var res *ua.RegisterNodesResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand All @@ -1176,7 +1176,7 @@ func (c *Client) UnregisterNodes(ctx context.Context, req *ua.UnregisterNodesReq
stats.Client().Add("NodesToUnregister", int64(len(req.NodesToUnregister)))

var res *ua.UnregisterNodesResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand All @@ -1199,7 +1199,7 @@ func (c *Client) HistoryReadEvent(ctx context.Context, nodes []*ua.HistoryReadVa
}

var res *ua.HistoryReadResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand All @@ -1222,7 +1222,7 @@ func (c *Client) HistoryReadRawModified(ctx context.Context, nodes []*ua.History
}

var res *ua.HistoryReadResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand All @@ -1245,7 +1245,7 @@ func (c *Client) HistoryReadProcessed(ctx context.Context, nodes []*ua.HistoryRe
}

var res *ua.HistoryReadResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand All @@ -1268,7 +1268,7 @@ func (c *Client) HistoryReadAtTime(ctx context.Context, nodes []*ua.HistoryReadV
}

var res *ua.HistoryReadResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand Down
8 changes: 4 additions & 4 deletions client_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *Client) Subscribe(ctx context.Context, params *SubscriptionParameters,
}

var res *ua.CreateSubscriptionResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
if err != nil {
Expand Down Expand Up @@ -110,7 +110,7 @@ func (c *Client) transferSubscriptions(ctx context.Context, ids []uint32) (*ua.T
}

var res *ua.TransferSubscriptionsResponse
err := c.Send(ctx, req, func(v interface{}) error {
err := c.Send(ctx, req, func(v ua.Response) error {
return safeAssign(v, &res)
})
return res, err
Expand Down Expand Up @@ -178,7 +178,7 @@ func (c *Client) sendRepublishRequests(ctx context.Context, sub *Subscription, a

debug.Printf("RepublishRequest: req=%s", debug.ToJSON(req))
var res *ua.RepublishResponse
err := c.SecureChannel().SendRequest(ctx, req, c.Session().resp.AuthenticationToken, func(v interface{}) error {
err := c.SecureChannel().SendRequest(ctx, req, c.Session().resp.AuthenticationToken, func(v ua.Response) error {
return safeAssign(v, &res)
})
debug.Printf("RepublishResponse: res=%s err=%v", debug.ToJSON(res), err)
Expand Down Expand Up @@ -549,7 +549,7 @@ func (c *Client) sendPublishRequest(ctx context.Context) (*ua.PublishResponse, e

dlog.Printf("PublishRequest: %s", debug.ToJSON(req))
var res *ua.PublishResponse
err := c.sendWithTimeout(ctx, req, c.publishTimeout(), func(v interface{}) error {
err := c.sendWithTimeout(ctx, req, c.publishTimeout(), func(v ua.Response) error {
return safeAssign(v, &res)
})
stats.RecordError(err)
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestClient_Send_DoesNotPanicWhenDisconnected(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = c.Send(context.Background(), &ua.ReadRequest{}, func(i interface{}) error {
err = c.Send(context.Background(), &ua.ReadRequest{}, func(i ua.Response) error {
return nil
})
verify.Values(t, "", err, ua.StatusBadServerNotConnected)
Expand Down
Loading
Loading