gnatsd modification to prevent an account from logging in repeatedly

Golang is cool, the code is simple and easy to understand. After a little look at the source code of gnatsd, it should be changed like this:


  1. First of all, you need to customize the authentication system. Each user needs to use a different user name for authentication and login.
  2. Modify server.users to add a clientid field to record the user id of the successful login. Of course, remember to lock the server when writing.
  3. The client adds a kicked variable as a flag.
  4. If the authentication is successful, check whether the clientid already exists in server.users. If so, search for the client in server.cliens, find the client and set the kicked flag of the client, and update the clientid of server.users to the current clientid.
  5. Check the client.kicked flag under read in client.readloop, if the flag is set, send a reentrant message to the client, and then closeconnection.
  6. Atomicity is guaranteed by protecting the server.users.client field with a lock in the server.
  7. After the client receives the reentrant error message, it needs to respond on the interface.

Problems with custom authentication system


The custom authentication system intends to use the external database Redis to store user and pwd.
Every time I go to Redis to query for authentication.
At this time, the local server.users list is not used for authentication, but is only used to save the clientid corresponding to the currently logged-in user.
The local configuration file may also be reloaded, so that the users list will be overwritten. Consider adding a userclientids list instead of using the original users list.

Problems when clustering


When using a cluster, the same account may log in to different instances. The above modification can only kick out the old client on the currently logged-in instance, while the connection is still maintained on other instances.
So you also need to broadcast a kickuser message to all other clusters.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325671427&siteId=291194637