Merge pull request #31 from special/fix/pointers-to-interfaces

Don't use pointers to interfaces
This commit is contained in:
Sarah Jamie Lewis 2017-11-02 14:32:55 -07:00 committed by GitHub
commit 1ed9265866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 11 deletions

View File

@ -51,7 +51,7 @@ func (rai *RicochetApplicationInstance) SendChatMessage(message string) {
rai.connection.Do(func() error { rai.connection.Do(func() error {
channel := rai.connection.Channel("im.ricochet.chat", channels.Outbound) channel := rai.connection.Channel("im.ricochet.chat", channels.Outbound)
if channel != nil { if channel != nil {
chatchannel, ok := (*channel.Handler).(*channels.ChatChannel) chatchannel, ok := channel.Handler.(*channels.ChatChannel)
if ok { if ok {
chatchannel.SendMessage(message) chatchannel.SendMessage(message)
} }

View File

@ -23,7 +23,7 @@ type Channel struct {
Type string Type string
Direction Direction Direction Direction
Handler *Handler Handler Handler
Pending bool Pending bool
ServerHostname string ServerHostname string
ClientHostname string ClientHostname string

View File

@ -45,7 +45,7 @@ func (cm *ChannelManager) OpenChannelRequest(chandler channels.Handler) (*channe
channel.ID = cm.nextFreeChannel channel.ID = cm.nextFreeChannel
cm.nextFreeChannel += 2 cm.nextFreeChannel += 2
channel.Type = chandler.Type() channel.Type = chandler.Type()
channel.Handler = &chandler channel.Handler = chandler
channel.Pending = true channel.Pending = true
channel.Direction = channels.Outbound channel.Direction = channels.Outbound
cm.channels[channel.ID] = channel cm.channels[channel.ID] = channel
@ -76,7 +76,7 @@ func (cm *ChannelManager) OpenChannelRequestFromPeer(channelID int32, chandler c
channel := new(channels.Channel) channel := new(channels.Channel)
channel.ID = channelID channel.ID = channelID
channel.Type = chandler.Type() channel.Type = chandler.Type()
channel.Handler = &chandler channel.Handler = chandler
channel.Pending = true channel.Pending = true
channel.Direction = channels.Inbound channel.Direction = channels.Inbound
@ -90,7 +90,7 @@ func (cm *ChannelManager) OpenChannelRequestFromPeer(channelID int32, chandler c
func (cm *ChannelManager) Channel(ctype string, way channels.Direction) *channels.Channel { func (cm *ChannelManager) Channel(ctype string, way channels.Direction) *channels.Channel {
var foundChannel *channels.Channel var foundChannel *channels.Channel
for _, channel := range cm.channels { for _, channel := range cm.channels {
if (*channel.Handler).Type() == ctype && channel.Direction == way { if channel.Handler.Type() == ctype && channel.Direction == way {
if foundChannel == nil { if foundChannel == nil {
foundChannel = channel foundChannel = channel
} else { } else {

View File

@ -203,11 +203,11 @@ func (rc *Connection) Process(handler Handler) error {
if len(packet.Data) == 0 { if len(packet.Data) == 0 {
rc.traceLog(fmt.Sprintf("removing channel %d", packet.Channel)) rc.traceLog(fmt.Sprintf("removing channel %d", packet.Channel))
rc.channelManager.RemoveChannel(packet.Channel) rc.channelManager.RemoveChannel(packet.Channel)
(*channel.Handler).Closed(utils.ChannelClosedByPeerError) channel.Handler.Closed(utils.ChannelClosedByPeerError)
} else { } else {
rc.traceLog(fmt.Sprintf("received packet on %v channel %d", (*channel.Handler).Type(), packet.Channel)) rc.traceLog(fmt.Sprintf("received packet on %v channel %d", channel.Handler.Type(), packet.Channel))
// Send The Ricochet Packet to the Handler // Send The Ricochet Packet to the Handler
(*channel.Handler).Packet(packet.Data[:]) channel.Handler.Packet(packet.Data[:])
} }
} else { } else {
// When a non-zero packet is received for an unknown // When a non-zero packet is received for an unknown
@ -297,10 +297,10 @@ func (rc *Connection) controlPacket(handler Handler, res *Protocol_Data_Control.
if cr.GetOpened() { if cr.GetOpened() {
rc.traceLog(fmt.Sprintf("channel of type %v opened on %v", channel.Type, id)) rc.traceLog(fmt.Sprintf("channel of type %v opened on %v", channel.Type, id))
(*channel.Handler).OpenOutboundResult(nil, cr) channel.Handler.OpenOutboundResult(nil, cr)
} else { } else {
rc.traceLog(fmt.Sprintf("channel of type %v rejected on %v", channel.Type, id)) rc.traceLog(fmt.Sprintf("channel of type %v rejected on %v", channel.Type, id))
(*channel.Handler).OpenOutboundResult(errors.New(""), cr) channel.Handler.OpenOutboundResult(errors.New(""), cr)
} }
} else if res.GetKeepAlive() != nil { } else if res.GetKeepAlive() != nil {

View File

@ -79,7 +79,7 @@ func (echobot *RicochetEchoBot) Connect(privateKeyFile string, hostname string)
channel := rc.Channel("im.ricochet.chat", channels.Outbound) channel := rc.Channel("im.ricochet.chat", channels.Outbound)
if channel != nil { if channel != nil {
log.Printf("Found Chat Channel") log.Printf("Found Chat Channel")
chatchannel, ok := (*channel.Handler).(*channels.ChatChannel) chatchannel, ok := channel.Handler.(*channels.ChatChannel)
if ok { if ok {
chatchannel.SendMessage(message) chatchannel.SendMessage(message)
} }