Skip to content

Expose IP address for Acceptor #395

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

Merged
merged 2 commits into from
Feb 5, 2020
Merged
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
17 changes: 16 additions & 1 deletion acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Acceptor struct {
dynamicQualifier bool
dynamicQualifierCount int
dynamicSessionChan chan *session
sessionAddr map[SessionID]net.Addr
sessionFactory
}

Expand Down Expand Up @@ -100,6 +101,12 @@ func (a *Acceptor) Stop() {
a.sessionGroup.Wait()
}

//Get remote IP address for a given session.
func (a *Acceptor) RemoteAddr(sessionID SessionID) (net.Addr, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are adding to the package api, could you add a comment here describing the method for api users that will be picked up by godoc?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment

addr, ok := a.sessionAddr[sessionID]
return addr, ok
}

//NewAcceptor creates and initializes a new Acceptor.
func NewAcceptor(app Application, storeFactory MessageStoreFactory, settings *Settings, logFactory LogFactory) (a *Acceptor, err error) {
a = &Acceptor{
Expand All @@ -108,6 +115,7 @@ func NewAcceptor(app Application, storeFactory MessageStoreFactory, settings *Se
settings: settings,
logFactory: logFactory,
sessions: make(map[SessionID]*session),
sessionAddr: make(map[SessionID]net.Addr),
}
if a.settings.GlobalSettings().HasSetting(config.DynamicSessions) {
if a.dynamicSessions, err = settings.globalSettings.BoolSetting(config.DynamicSessions); err != nil {
Expand Down Expand Up @@ -265,6 +273,7 @@ func (a *Acceptor) handleConnection(netConn net.Conn) {
defer session.stop()
}

a.sessionAddr[sessID] = netConn.RemoteAddr()
msgIn := make(chan fixIn)
msgOut := make(chan []byte)

Expand Down Expand Up @@ -309,7 +318,13 @@ LOOP:
complete <- sessionID
}()
case id := <-complete:
delete(sessions, id)
session, ok := sessions[id]
if ok {
delete(a.sessionAddr, session.sessionID)
delete(sessions, id)
} else {
a.globalLog.OnEventf("Missing dynamic session %v!", id)
}
}
}

Expand Down