Skip to content

Commit

Permalink
Merge pull request #205 from special/file-transfer-prereq
Browse files Browse the repository at this point in the history
Assorted minor changes from developing file transfers
  • Loading branch information
special committed Jul 7, 2015
2 parents b50be68 + 35cea24 commit 375ad5c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/core/ContactUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,10 @@ void ContactUser::onConnected()
}

updateStatus();
if (isConnected())
if (isConnected()) {
emit connected();
emit connectionChanged(m_connection);
}

if (m_status != Online && m_status != RequestPending) {
BUG() << "Contact has a connection while in status" << m_status << "which is not expected.";
Expand All @@ -258,6 +260,7 @@ void ContactUser::onDisconnected()

updateStatus();
emit disconnected();
emit connectionChanged(0);
}

SettingsObject *ContactUser::settings()
Expand Down
1 change: 1 addition & 0 deletions src/core/ContactUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public slots:
void statusChanged();
void connected();
void disconnected();
void connectionChanged(Protocol::Connection *connection);

void nicknameChanged();
void contactDeleted(ContactUser *user);
Expand Down
5 changes: 3 additions & 2 deletions src/core/ContactsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ void ContactsManager::loadFromSettings()
continue;
}

ContactUser *user = new ContactUser(identity, id, this);
ContactUser *user = new ContactUser(identity, id, this);
connectSignals(user);
pContacts.append(user);
pContacts.append(user);
emit contactAdded(user);
highestID = qMax(id, highestID);
}

Expand Down
18 changes: 18 additions & 0 deletions src/protocol/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ bool ChannelPrivate::openChannelInbound(const Data::Control::OpenChannel *reques
if (!q->allowInboundChannelRequest(request, result))
return false;

if (isInvalidated) {
// This can happen as a result of something calling closeChannel under the
// allowInboundChannelRequest handler, which can't be easily ruled out due
// to signals. Treat is as a generic error and fail the channel.
result->set_opened(false);
return false;
}

if (result->has_common_error()) {
BUG() << "Accepted inbound OpenChannel request, but result has error details set. Assuming it's actually an error.";
result->set_opened(false);
Expand Down Expand Up @@ -267,6 +275,16 @@ bool Channel::sendPacket(const QByteArray &packet)
return connection()->d->writePacket(this, packet);
}

void Channel::requestInboundApproval()
{
if (direction() != Channel::Inbound || isOpened()) {
BUG() << "Called in an unexpected channel state";
return;
}

emit connection()->channelRequestingInboundApproval(this);
}

ChannelPrivate::ChannelPrivate(Channel *q, const QString &type, Channel::Direction direction, Connection *conn)
: q_ptr(q)
, connection(conn)
Expand Down
18 changes: 18 additions & 0 deletions src/protocol/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ public slots:
*/
template<typename T> bool sendMessage(const T &message);

/* Get approval for an inbound channel from the Connection's handlers
*
* Channels that require approval from higher-layer functionality before
* opening can use this method to emit the
* Connection::channelRequestingInboundApproval signal. For example, this
* can be used to look up whether an identifier for a channel is recognized,
* and allow higher layers to attach signals and update data before the
* channel is fully open.
*
* Approval should be signaled to the channel by means of some
* channel-specific API; in many cases, that might involve setting certain
* properties that the channel requires.
*
* This method may only be called from within the
* allowInboundChannelRequest handler.
*/
void requestInboundApproval();

QScopedPointer<ChannelPrivate> d_ptr;
};

Expand Down
11 changes: 11 additions & 0 deletions src/protocol/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ public slots:
* channelClosed signal.
*/
void channelCreated(Channel *channel);
/* Emitted when an inbound channel needs approval to open
*
* This signal is emitted for channel types that require approval by
* higher-layer functionality before opening, based on the information
* in the OpenChannel message. Handlers should use channel-specific methods
* to approve the inbound channel.
*
* This signal is only emitted for channels that specifically invoke the
* Channel::requestInboundApproval() method.
*/
void channelRequestingInboundApproval(Channel *channel);
/* Emitted when a channel is opened
*
* This signal is emitted after an inbound or outbound channel has been
Expand Down
4 changes: 3 additions & 1 deletion src/protocol/OutboundConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ void OutboundConnectorPrivate::startAuthentication()
}

if (!authPrivateKey.isLoaded() || !authPrivateKey.isPrivate()) {
setError(QStringLiteral("Cannot authenticate outbound connection without a valid private key"));
qDebug() << "Skipping authentication for OutboundConnector without a private key";
setStatus(OutboundConnector::Ready);
emit q->ready();
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/ui/qml/ChatMessageArea.qml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ ScrollView {
ListView {
id: messageView
spacing: 12
pixelAligned: true

header: Item { width: 1; height: messageView.spacing }
footer: Item { width: 1; height: messageView.spacing }
Expand Down

0 comments on commit 375ad5c

Please sign in to comment.