nauful / LibUA

Open-source OPC UA client and server library
Apache License 2.0
262 stars 94 forks source link

Question about usage Server #127

Closed franklupo closed 1 year ago

franklupo commented 1 year ago

Hi, First I wanted to thank you for your great work for this great library.

best regards

nauful commented 1 year ago

Hello,

Glad you like my library.

IP binding

I don't expose this by default but you can promote IPEndPoint to a parameter for this function: https://github.com/nauful/LibUA/blob/c8e642d10b1f39543bc1487c8e0fa496ef743b17/NET%20Core/LibUA/Server.cs#L60 Then you can pass in an ip to bind to here: https://github.com/nauful/LibUA/blob/c8e642d10b1f39543bc1487c8e0fa496ef743b17/NET%20Core/TestServer/Program.cs#L590

For user-level permissions,

Create a session object (any type of your design) and return a new instance here: https://github.com/nauful/LibUA/blob/c8e642d10b1f39543bc1487c8e0fa496ef743b17/NET%20Core/TestServer/Program.cs#L105C41-L105C61 E.g. session.state == Unassigned now When the client sends a username + password, assign it to your session object here: https://github.com/nauful/LibUA/blob/c8e642d10b1f39543bc1487c8e0fa496ef743b17/NET%20Core/TestServer/Program.cs#L138 E.g. session.state == Logged in, session.username == username now Implement this in your Application: https://github.com/nauful/LibUA/blob/c8e642d10b1f39543bc1487c8e0fa496ef743b17/NET%20Core/LibUA/Application.cs#L633 Now you can check if session[Logged in, username] has permission to access any particular NodeId.

Storage

For memory I use a Dictionary<NodeId, MyDataTypes>. For storage you can use a normal database (sqlite, MySql, etc) or any time-series database (my original use case when I started this library). You can write to Dictionary and db when receiving a ua write, read from dictionary or read from db and cache in dictionary.

franklupo commented 1 year ago

Hi,

IP binding

https://github.com/nauful/LibUA/blob/c8e642d10b1f39543bc1487c8e0fa496ef743b17/NET%20Core/LibUA/Server.cs#L35C11-L35C17it would be nice to pass endpoint to constructor

For user-level permissions,

https://github.com/nauful/LibUA/blob/c8e642d10b1f39543bc1487c8e0fa496ef743b17/NET%20Core/LibUA/Application.cs#L633 the SessionHasPermissionToRead is not virtual, ovveride is not possible

best regards

nauful commented 1 year ago

Done both, please try now.

nauful commented 1 year ago

Closed, finished work.