From c38ad188881623bd31880d1cbcb168e0bff9440c Mon Sep 17 00:00:00 2001 From: John Brooks Date: Wed, 30 Nov 2016 19:37:19 -0800 Subject: [PATCH] Update to match my protocol API changes branch --- core/protocol.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/core/protocol.go b/core/protocol.go index 6bc3924..c1d90df 100644 --- a/core/protocol.go +++ b/core/protocol.go @@ -109,20 +109,19 @@ func (pc *ProtocolConnection) OnContactRequestAck(channelID int32, status string } } -// Managing Channels -func (pc *ProtocolConnection) IsChannelAllowed(channelType string) bool { - switch channelType { - case "im.ricochet.auth.hidden-service": - return !pc.Conn.IsAuthed && pc.Contact == nil - case "im.ricochet.chat": - return pc.Conn.IsAuthed && pc.Contact != nil - case "im.ricochet.contact.request": - return pc.Conn.IsAuthed && pc.Contact == nil +func (pc *ProtocolConnection) IsKnownContact(hostname string) bool { + // All uses of this are for authenticated contacts, so it's sufficient to check pc.Contact + if pc.Contact != nil { + contactHostname, _ := PlainHostFromOnion(pc.Contact.Hostname()) + if hostname != contactHostname { + log.Panicf("IsKnownContact called for unexpected hostname '%s'", hostname) + } + return true } - return false } +// Managing Channels func (pc *ProtocolConnection) OnOpenChannelRequest(channelID int32, channelType string) { log.Printf("open channel request: %v %v", channelID, channelType) pc.Conn.AckOpenChannel(channelID, channelType)