Skip to content

UDP event listeners live forever #7

@goharahmed

Description

@goharahmed

Hi,
Probably my poor understanding of the code but it seems like the UDP event listener function are never ending loops. I've a test setup where initially sending a mi rpc request via call-api-client, call-api created a newer UDP local listener which never gets terminated.

Here is what I've understood is happening:

STEP1:

Create a NewProxy object every time a new wss/ws client sends request! (Can we not reuse older ones?)
NewProxy() has two major tasks.
1 - Establish connection to the opensips mi-datagram socket
2 - Create an event listener which can do subscriptions and filter on events

STEP2:

NewProxy() must connect to the opensips mi_datagram socket for sending commands, but to return a response/event it creates another UDP connection to the OpenSIPS mi_datagram socket.? Could we not have used the first connection's LocalAddr() instead.

func (event *EventDatagram) Init(mi mi.MI) (error) {

	miAddr, ok := mi.Addr().(*net.UDPAddr)
	if ok != true {
		return errors.New("using non-UDP protocol to connect to MI")
	}
	c, err := net.DialUDP("udp", nil, miAddr)
	if err != nil {
		return err
	}
	udpAddr, ok := c.LocalAddr().(*net.UDPAddr)
	if ok != true {
		return errors.New("using non-UDP local socket to connect to MI")
	}
	local := net.UDPAddr{IP: udpAddr.IP}
	udpConn, err := net.ListenUDP(c.LocalAddr().Network(), &local)
	if err != nil {
		return err
	}

EventHandler created another UDPConn to opensips mi_datagram socket and setup a goroutine waitForEvents()

STEP3:

waitForEvents() create a never expiring/ending for loop on the local side of the second mi_datagram UDPConn. Untill some error happens this doesn't break !

image

Questions:
Is this correct understanding?
Can we reuse the first established socket to mi_datagram for both sending commands and receiving replies for all incoming wss clients. Right now, every new WSS client sending command created a few sockets which live way longer than needed.

I'm implementing mi_http interface here, do I really need to have Events subscriptions or waitforEvents() functions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions