Skip to content
This repository has been archived by the owner on Mar 4, 2023. It is now read-only.

Refusing connection #14

Open
ecoshub opened this issue Nov 2, 2020 · 6 comments
Open

Refusing connection #14

ecoshub opened this issue Nov 2, 2020 · 6 comments

Comments

@ecoshub
Copy link
Contributor

ecoshub commented Nov 2, 2020

Hi @thinkgos Thank you for this project it is working great so far.

I am wondering if there is a way to refuse a connection from server.

I have a server and multiple clients, can I limit the connect to server?.

I have try to close "UnderlyingConn()" but clients keep trying connect with attempt.

Do you have any other idea, maybe sending an ASDU like StopDT from server?

@thinkgos
Copy link
Owner

thinkgos commented Nov 3, 2020

If add a return error on OnConnectHandler api?? if return error, indicate refuse the connection from server?? It seem like a idea.

@ecoshub
Copy link
Contributor Author

ecoshub commented Nov 3, 2020

OnConnectionHandler does not implement a return error statement. Do you mean should I implement the return error statement to the source code ?

// SetOnConnectionHandler set on connect handler
func (sf *Server) SetOnConnectionHandler(f func(asdu.Connect)) {
	sf.onConnection = f
}

if I refuse connections by closing them client is attempting in a infinite loop.

mainServer = cs104.NewServer(&myServer{})
mainServer.SetOnConnectionHandler(func(asd asdu.Connect){
	asd.UnderlyingConn().Close()
})

@thinkgos
Copy link
Owner

thinkgos commented Nov 3, 2020

@ecoshub YES,OnConnectionHandler should implement a return error statement to the source code.

// SetOnConnectionHandler set on connect handler
func (sf *Server) SetOnConnectionHandler(f func(asdu.Connect) error ) {
	sf.onConnection = f
}

in the file server_session.go line 206 - 218

	defer func() {
		sf.setConnectStatus(disconnected)
		checkTicker.Stop()
		_ = sf.conn.Close() // 连锁引发cancel
		sf.wg.Wait()
		if sf.connectionLost != nil {
			sf.connectionLost(sf)
		}
		sf.Debug("run stopped!")
	}()

       if err := sf.onConnection(sf);err!= nil{
           return
      }

we can not forbid the client attempting in a infinite loop. only we can do, just refuse it.

what about this idea?

@ecoshub
Copy link
Contributor Author

ecoshub commented Nov 3, 2020

Yes I am currently doing that without implementing any other code to the source code. I am just closing the connection with asdu.UnderlyingConn().Close(). That is not the case.

Let me rephrase the question. Does iec 60870-5 104 protocol has any ASDU command for closing the connection from server like client do with StopDT and does this package has any thing like that?

@thinkgos
Copy link
Owner

thinkgos commented Nov 3, 2020

sorry ,I can not find. you can refer to lib60870 c library lib60870 doc, maybe you can get an idea.

@ecoshub
Copy link
Contributor Author

ecoshub commented Nov 3, 2020

Thank you so much for your help I will read doc again for an answer. If there is no answer for my question in the doc I will try to find out a solution and post it from here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants