最近一直在学习SSL相关知识,也明白了理论相关知识,主要SSL基本概念和连接建立。主要依据PolarSSL开源库学习。学习完了之后就希望能给有所运用,就想用Qt写一个简单的程序,添加对SSL相关概念的把握和对PolarSSL库的运用。当然,终于希望是能够使用Qt做一个比較完好的工具,帮助大家更好的理解和学习SSL相关知识。这都是后话,在第一篇里面,我们就简单用样例展示怎样在Qt里面调用PolarSSL库。

这篇博客主要是解说Qt里面调用PolarSSL库,至于SSL相关概念在后面的博客再具体介绍。

SSL握手须要客户端和服务器端交互。这里我们分别介绍。

1、编译PolarSSL库

我们准备使用的方式就是编译PolarSSL为.a静态库,然后在Qt中连接,使用的PolarSSL的版本号是0.10.1。

下载相应的软件版本号。解压缩后在library文件夹下执行make就可以生成libpolarssl.a库文件,例如以下图:

2、服务器端

使用Qt设计一个简单的界面。在button的槽函数中进行相关的操作。也就是调用PolarSSL库函数进行编程。初始化ssl相关结构体,监听port。等等。

SSL中最重要的就是执行握手操作。这里须要注意一点,因为涉及到socket编程。像accept函数都是堵塞的。假设在gui主线程中调用会造成界面冻结,也就是我们常说的ANR。解决方法就是将这些操作放在一个线程中,Qt中创建一个线程比較easy。创建一个类,继承自QThread,实现run函数。就可以。最后启动线程也比較简单,调用该类的start()

函数就可以。

好了,不多说了。上代码。首先看看服务器端的代码结构:workThread即是线程。实现SSL相关的功能,监听套接字,实现SSL握手,读取客户端发来的消息,向客户端发送消息。

mianwindow即是主窗体界面,有个button,在button的槽函数中启动线程

代码:

project文件:

#-------------------------------------------------
#
# Project created by QtCreator 2014-05-11T22:28:07
#
#------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = MyPolarSSLToolSrv
TEMPLATE = app INCLUDEPATH += /home/chenlong12580/develop/polarTool/polarssl/include
LIBS += -L "/home/chenlong12580/develop/polarTool/polarssl/lib/" -lpolarssl SOURCES += main.cpp\
widget.cpp \
workthread.cpp HEADERS += widget.h \
workthread.h FORMS += widget.ui

线程类:

void WorkThread::run()
{
qDebug() << "I am a thread!"; int listen_fd = 0;
int client_fd =0;
int ret= 0;
havege_state hs;
ssl_context ssl;
ssl_session ssn;
x509_cert srvcert;
rsa_context rsa;
unsigned char buf[1024];
int len = 0; memset( &srvcert, 0, sizeof( x509_cert ) ); ret = x509parse_crt( &srvcert, (unsigned char *) test_srv_crt,
strlen( test_srv_crt ) );
if( ret != 0 )
{
printf( " failed\n ! x509parse_crt returned %d\n\n", ret );
return;
} ret = x509parse_crt( &srvcert, (unsigned char *) test_ca_crt,
strlen( test_ca_crt ) );
if( ret != 0 )
{
printf( " failed\n ! x509parse_crt returned %d\n\n", ret );
return;
} ret = x509parse_key( &rsa, (unsigned char *) test_srv_key,
strlen( test_srv_key ), NULL, 0 );
if( ret != 0 )
{
printf( " failed\n ! x509parse_key returned %d\n\n", ret );
return;
} ret = net_bind( &listen_fd, NULL, 8443 );
if (0 != ret)
{
qDebug() << ret;
return;
} qDebug() << "bind ok"; /* socket is block */
ret = net_accept( listen_fd, &client_fd, NULL );
if (0 != ret)
{
return;
} qDebug() << "accept ok"; havege_init( &hs ); ret = ssl_init( &ssl );
if (0 != ret)
{
return;
} ssl_set_endpoint( &ssl, SSL_IS_SERVER );
ssl_set_authmode( &ssl, SSL_VERIFY_NONE ); ssl_set_rng( &ssl, havege_rand, &hs );
ssl_set_dbg( &ssl, my_debug, stdout );
ssl_set_bio( &ssl, net_recv, &client_fd,
net_send, &client_fd );
ssl_set_scb( &ssl, my_get_session,
my_set_session ); ssl_set_ciphers( &ssl, my_ciphers );
ssl_set_session( &ssl, 1, 0, &ssn ); memset( &ssn, 0, sizeof( ssl_session ) ); ssl_set_ca_chain( &ssl, srvcert.next, NULL );
ssl_set_own_cert( &ssl, &srvcert, &rsa );
ssl_set_dh_param( &ssl, my_dhm_P, my_dhm_G ); qDebug() << "before ssl_handshake ok"; while( ( ret = ssl_handshake( &ssl ) ) != 0 )
{
;
} qDebug() << "ssl_handshake ok"; do
{
len = sizeof( buf ) - 1;
memset( buf, 0, sizeof( buf ) );
ret = ssl_read( &ssl, buf, len ); if( ret == POLARSSL_ERR_NET_TRY_AGAIN )
continue; if( ret <= 0 )
{
switch( ret )
{
case POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY:
printf( " connection was closed gracefully\n" );
break; case POLARSSL_ERR_NET_CONN_RESET:
printf( " connection was reset by peer\n" );
break; default:
printf( " ssl_read returned %d\n", ret );
break;
} break;
} len = ret;
printf( " %d bytes read\n\n%s", len, (char *) buf );
}while( 0 ); char *cc = (char *)buf;
QString ss(cc); qDebug() << ss; (void)sprintf( (char *) buf, HTTP_RESPONSE,
ssl_get_cipher( &ssl ) ); while( ( ret = ssl_write( &ssl, buf, len ) ) <= 0 )
{
if( ret == POLARSSL_ERR_NET_CONN_RESET )
{
printf( " failed\n ! peer closed the connection\n\n" );
return;
} if( ret != POLARSSL_ERR_NET_TRY_AGAIN )
{
printf( " failed\n ! ssl_write returned %d\n\n", ret );
return;
}
} ssl_close_notify( &ssl ); net_close( client_fd );
x509_free( &srvcert );
rsa_free( &rsa );
ssl_free( &ssl ); cur = s_list_1st;
while( cur != NULL )
{
prv = cur;
cur = cur->next;
memset( prv, 0, sizeof( ssl_session ) );
free( prv );
} memset( &ssl, 0, sizeof( ssl_context ) );
}

主窗体类:

#include "widget.h"
#include "ui_widget.h"
#include <QFileDialog>
#include <QDebug>
#include <QMessageBox>
#include "workthread.h"
#include "polarssl/havege.h"
#include "polarssl/certs.h"
#include "polarssl/x509.h"
#include "polarssl/ssl.h"
#include "polarssl/net.h" Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this); qDebug() << "server"; connect(this, SIGNAL(emit_parse_cer()), this, SLOT(slot_parse_cer()));
} Widget::~Widget()
{
delete ui;
} void Widget::on_BrowseBtn_clicked()
{
QString pathStr = QFileDialog::getOpenFileName(this, QString("选择证书文件"), QString("C:\\Users\\Administrator\\Desktop"), QString("*.*"));
if (pathStr.length() == 0)
{
qDebug() << "please select a cer file!";
return;
} ui->PathEdit->setText(pathStr); emit emit_parse_cer();
} void Widget::slot_parse_cer()
{
x509_cert crt;
memset(&crt, 0, sizeof(crt)); int res = x509parse_crtfile( &crt, ui->PathEdit->text().toLatin1().data());
if (0 != res)
{
QMessageBox::warning(this, "警告", "解析证书失败,请选择正确的证书文件", QMessageBox::Ok);
return;
} ui->CrtInfo->setText(QString("是否为根证书:") + QString::number(crt.ca_istrue));
ui->CrtInfo->append(QString("证书版本号号:") + QString::number(crt.version));
ui->CrtInfo->append(QString("有效期:") + QString::number(crt.valid_from.year) + "-" + QString::number(crt.valid_from.mon)
+ QString(" 到:") + QString::number(crt.valid_to.year) + "-" + QString::number(crt.valid_to.mon)); qDebug() << crt.ca_istrue;
qDebug() << crt.valid_from.year;
} void Widget::on_pushButton_clicked()
{
WorkThread *workThread = new WorkThread;
workThread->start();
}

3、客户端

客户端比較简单,直接在界面类进行的SSL功能相关的实现,就是创建套接字,链接服务器,进行SSL握手,向服务器发消息,读取服务器发来的消息。

project文件:

#-------------------------------------------------
#
# Project created by QtCreator 2014-05-11T22:28:07
#
#------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = MyPolarSSLToolCli
TEMPLATE = app INCLUDEPATH += /home/chenlong12580/develop/polarTool/polarssl/include
LIBS += -L "/home/chenlong12580/develop/polarTool/polarssl/lib/" -lpolarssl SOURCES += main.cpp\
widget.cpp HEADERS += widget.h FORMS += widget.ui

主窗体类:

#include "widget.h"
#include "ui_widget.h"
#include <QFileDialog>
#include <QDebug>
#include <QMessageBox>
#include "polarssl/havege.h"
#include "polarssl/certs.h"
#include "polarssl/x509.h"
#include "polarssl/ssl.h"
#include "polarssl/net.h" #define SERVER_PORT 8443
/*
#define SERVER_NAME "localhost"
#define GET_REQUEST "GET / HTTP/1.0\r\n\r\n"
*/
#define SERVER_NAME "polarssl.org"
#define GET_REQUEST \
"GET /hello/ HTTP/1.1\r\n" \
"Host: polarssl.org\r\n\r\n" #define DEBUG_LEVEL 0 void my_debug( void *ctx, int level, char *str )
{
if( level < DEBUG_LEVEL )
{
fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
} Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this); qDebug() << "client"; connect(this, SIGNAL(emit_parse_cer()), this, SLOT(slot_parse_cer()));
} Widget::~Widget()
{
delete ui;
} void Widget::on_BrowseBtn_clicked()
{
QString pathStr = QFileDialog::getOpenFileName(this, QString("选择证书文件"), QString("C:\\Users\\Administrator\\Desktop"), QString("*.*"));
if (pathStr.length() == 0)
{
qDebug() << "please select a cer file!";
return;
} ui->PathEdit->setText(pathStr); emit emit_parse_cer();
} void Widget::slot_parse_cer()
{
x509_cert crt;
memset(&crt, 0, sizeof(crt)); int res = x509parse_crtfile( &crt, ui->PathEdit->text().toLatin1().data());
if (0 != res)
{
QMessageBox::warning(this, "警告", "解析证书失败,请选择正确的证书文件", QMessageBox::Ok);
return;
} ui->CrtInfo->setText(QString("是否为根证书:") + QString::number(crt.ca_istrue));
ui->CrtInfo->append(QString("证书版本号号:") + QString::number(crt.version));
ui->CrtInfo->append(QString("有效期:") + QString::number(crt.valid_from.year) + "-" + QString::number(crt.valid_from.mon)
+ QString(" 到:") + QString::number(crt.valid_to.year) + "-" + QString::number(crt.valid_to.mon)); qDebug() << crt.ca_istrue;
qDebug() << crt.valid_from.year;
} void Widget::on_pushButton_clicked()
{
int ret, len, server_fd;
unsigned char buf[1024];
havege_state hs;
ssl_context ssl;
ssl_session ssn; /*
* 0. Initialize the RNG and the session data
*/
havege_init( &hs );
memset( &ssn, 0, sizeof( ssl_session ) ); /*
* 1. Start the connection
*/
printf( "\n . Connecting to tcp/%s/%4d...", SERVER_NAME,
SERVER_PORT );
fflush( stdout ); if( ( ret = net_connect( &server_fd, "127.0.0.1",
SERVER_PORT ) ) != 0 )
{
printf( " failed\n ! net_connect returned %d\n\n", ret );
return;
} printf( " ok\n" ); /*
* 2. Setup stuff
*/
printf( " . Setting up the SSL/TLS structure..." );
fflush( stdout ); if( ( ret = ssl_init( &ssl ) ) != 0 )
{
printf( " failed\n ! ssl_init returned %d\n\n", ret );
return;
} printf( " ok\n" ); ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
ssl_set_authmode( &ssl, SSL_VERIFY_NONE ); ssl_set_rng( &ssl, havege_rand, &hs );
ssl_set_dbg( &ssl, my_debug, stdout );
ssl_set_bio( &ssl, net_recv, &server_fd,
net_send, &server_fd ); ssl_set_ciphers( &ssl, ssl_default_ciphers );
ssl_set_session( &ssl, 1, 600, &ssn ); /*
* 3. Write the GET request
*/
printf( " > Write to server:" );
fflush( stdout ); len = sprintf( (char *) buf, GET_REQUEST ); while( ( ret = ssl_write( &ssl, buf, len ) ) <= 0 )
{
if( ret != POLARSSL_ERR_NET_TRY_AGAIN )
{
printf( " failed\n ! ssl_write returned %d\n\n", ret );
return;
}
} len = ret;
printf( " %d bytes written\n\n%s", len, (char *) buf ); /*
* 7. Read the HTTP response
*/
printf( " < Read from server:" );
fflush( stdout ); do
{
len = sizeof( buf ) - 1;
memset( buf, 0, sizeof( buf ) );
ret = ssl_read( &ssl, buf, len ); if( ret == POLARSSL_ERR_NET_TRY_AGAIN )
continue; if( ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY )
break; if( ret <= 0 )
{
printf( "failed\n ! ssl_read returned %d\n\n", ret );
break;
} len = ret;
printf( " %d bytes read\n\n%s", len, (char *) buf );
}
while( 0 ); char *cc= (char *)buf;
QString ss(cc); qDebug() << ss; ssl_close_notify( &ssl ); return;
}

4、执行效果

以下说说执行的效果,首先启动服务器端。服务器端启动线程,监听套接字:

接着启动客户端。客户端链接服务器端,写入消息,读取服务器端的响应:

最后依据打印能够看出服务器端和客户端握手成功。写入读取消息成功:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hlbmxvbmcxMjU4MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

我们能够依据抓包来看看SSL握手的过程。例如以下:

通过抓包能够看到服务器端和客户端的握手过程,以及在不同的握手阶段中做得事情:

服务器端:

/*
* SSL handshake -- server side
*/
int ssl_handshake_server( ssl_context *ssl )
{
int ret = 0; SSL_DEBUG_MSG( 2, ( "=> handshake server" ) ); while( ssl->state != SSL_HANDSHAKE_OVER )
{
SSL_DEBUG_MSG( 2, ( "server state: %d", ssl->state ) ); if( ( ret = ssl_flush_output( ssl ) ) != 0 )
break; switch( ssl->state )
{
case SSL_HELLO_REQUEST:
ssl->state = SSL_CLIENT_HELLO;
break; /*
* <== ClientHello
*/
case SSL_CLIENT_HELLO:
ret = ssl_parse_client_hello( ssl );
break; /*
* ==> ServerHello
* Certificate
* ( ServerKeyExchange )
* ( CertificateRequest )
* ServerHelloDone
*/
case SSL_SERVER_HELLO:
ret = ssl_write_server_hello( ssl );
break; case SSL_SERVER_CERTIFICATE:
ret = ssl_write_certificate( ssl );
break; case SSL_SERVER_KEY_EXCHANGE:
ret = ssl_write_server_key_exchange( ssl );
break; case SSL_CERTIFICATE_REQUEST:
ret = ssl_write_certificate_request( ssl );
break; case SSL_SERVER_HELLO_DONE:
ret = ssl_write_server_hello_done( ssl );
break; /*
* <== ( Certificate/Alert )
* ClientKeyExchange
* ( CertificateVerify )
* ChangeCipherSpec
* Finished
*/
case SSL_CLIENT_CERTIFICATE:
ret = ssl_parse_certificate( ssl );
break; case SSL_CLIENT_KEY_EXCHANGE:
ret = ssl_parse_client_key_exchange( ssl );
break; case SSL_CERTIFICATE_VERIFY:
ret = ssl_parse_certificate_verify( ssl );
break; case SSL_CLIENT_CHANGE_CIPHER_SPEC:
ret = ssl_parse_change_cipher_spec( ssl );
break; case SSL_CLIENT_FINISHED:
ret = ssl_parse_finished( ssl );
break; /*
* ==> ChangeCipherSpec
* Finished
*/
case SSL_SERVER_CHANGE_CIPHER_SPEC:
ret = ssl_write_change_cipher_spec( ssl );
break; case SSL_SERVER_FINISHED:
ret = ssl_write_finished( ssl );
break; case SSL_FLUSH_BUFFERS:
SSL_DEBUG_MSG( 2, ( "handshake: done" ) );
ssl->state = SSL_HANDSHAKE_OVER;
break; default:
SSL_DEBUG_MSG( 1, ( "invalid state %d", ssl->state ) );
return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
} if( ret != 0 )
break;
} SSL_DEBUG_MSG( 2, ( "<= handshake server" ) ); return( ret );
}

客户端:

/*
* SSL handshake -- client side
*/
int ssl_handshake_client( ssl_context *ssl )
{
int ret = 0; SSL_DEBUG_MSG( 2, ( "=> handshake client" ) ); while( ssl->state != SSL_HANDSHAKE_OVER )
{
SSL_DEBUG_MSG( 2, ( "client state: %d", ssl->state ) ); if( ( ret = ssl_flush_output( ssl ) ) != 0 )
break; switch( ssl->state )
{
case SSL_HELLO_REQUEST:
ssl->state = SSL_CLIENT_HELLO;
break; /*
* ==> ClientHello
*/
case SSL_CLIENT_HELLO:
ret = ssl_write_client_hello( ssl );
break; /*
* <== ServerHello
* Certificate
* ( ServerKeyExchange )
* ( CertificateRequest )
* ServerHelloDone
*/
case SSL_SERVER_HELLO:
ret = ssl_parse_server_hello( ssl );
break; case SSL_SERVER_CERTIFICATE:
ret = ssl_parse_certificate( ssl );
break; case SSL_SERVER_KEY_EXCHANGE:
ret = ssl_parse_server_key_exchange( ssl );
break; case SSL_CERTIFICATE_REQUEST:
ret = ssl_parse_certificate_request( ssl );
break; case SSL_SERVER_HELLO_DONE:
ret = ssl_parse_server_hello_done( ssl );
break; /*
* ==> ( Certificate/Alert )
* ClientKeyExchange
* ( CertificateVerify )
* ChangeCipherSpec
* Finished
*/
case SSL_CLIENT_CERTIFICATE:
ret = ssl_write_certificate( ssl );
break; case SSL_CLIENT_KEY_EXCHANGE:
ret = ssl_write_client_key_exchange( ssl );
break; case SSL_CERTIFICATE_VERIFY:
ret = ssl_write_certificate_verify( ssl );
break; case SSL_CLIENT_CHANGE_CIPHER_SPEC:
ret = ssl_write_change_cipher_spec( ssl );
break; case SSL_CLIENT_FINISHED:
ret = ssl_write_finished( ssl );
break; /*
* <== ChangeCipherSpec
* Finished
*/
case SSL_SERVER_CHANGE_CIPHER_SPEC:
ret = ssl_parse_change_cipher_spec( ssl );
break; case SSL_SERVER_FINISHED:
ret = ssl_parse_finished( ssl );
break; case SSL_FLUSH_BUFFERS:
SSL_DEBUG_MSG( 2, ( "handshake: done" ) );
ssl->state = SSL_HANDSHAKE_OVER;
break; default:
SSL_DEBUG_MSG( 1, ( "invalid state %d", ssl->state ) );
return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
} if( ret != 0 )
break;
} SSL_DEBUG_MSG( 2, ( "<= handshake client" ) ); return( ret );
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

Qt调用PolarSSL库(一个)的更多相关文章

  1. Qt中调用PolarSSL库(一)

    最近一直在学习SSL相关的知识,也是先了解理论相关的知识,主要是SSL相关的基本概念和连接建立过程,主要是基于PolarSSL开源库进行学习.学习完了之后就希望能给有所运用,就想用Qt写一个简单的程序 ...

  2. Linux下Qt调用共享库文件.so

    修改已有的pro文件,添加如下几句: INCLUDEPATH += /home/ubuntu/camera/camera/LIBS += -L/home/ubuntu/camera/camera -l ...

  3. qt调用仪器驱动库dll实现程控

    在<使用qt+visa实现程控>中实现了qt调用visa库的简单Demo本文将尝试使用qt调用仪器驱动库来实现对仪器仪表的程控 开发环境 系统: windows 10 环境: qt 5.8 ...

  4. QT 调用VS2015编写的Dll

    最近在用QT调用VC生成的库,QT使用的是MinGW调试器,出现与动态库不兼容的问题,最后发现QT只能识别VC生成的C格式下的动态库 也就是在导入导出设置时加入extern "C" ...

  5. Qt打开外部程序和文件夹需要注意的细节(Qt调用VC写的动态库,VC需要用C的方式输出函数,否则MinGW32编译过程会报错)

    下午写程序中遇到几个小细节,需要在这里记录一下. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 QProcess *process = new QProcess(this ...

  6. Qt生成和调用动态库dll,和静态库.a(windows和linux通用)

    系统1:ThinkPad T570.Windows10.QT5.12.2(Qt Creater 4.8.2)一.动态库.dll的创建和调用1.在qtcreater中按如下步骤创建动态库,动态库名为my ...

  7. windows下Qt Creator5.1.0编写程序以及调用OpenCV库

    系统说明 最近使用opencv编写程序,程序编的差不多就学习使用QT加个界面,首先声明下本人的系统和使用的软件版本, 系统: windows xp QT IDE:QT Creator5.1.0 Ope ...

  8. 【Qt官方MQTT库的使用,附一个MqttClient例子】

    Qt官方MQTT库的使用,附一个MqttClient例子 开发环境:win7 64 + Qt5.9 记录时间:2018年3月11日 00:48:42 联系邮箱: yexiaopeng1992@126. ...

  9. 一个简单的C共享库的创建及Python调用此库的方法

    /********************************************************************* * Author  : Samson * Date    ...

随机推荐

  1. 【53.57%】【codeforces 722D】Generating Sets

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. JAVA学习路线图---(JAVA1234) 分类: B1_JAVA 2013-10-05 10:22 502人阅读 评论(1) 收藏

    转自:http://blog.csdn.net/pplcheer/article/details/12276999 第一阶段-Java基础        这一阶段很重要,关系到你后面阶段的学习,所以务 ...

  3. svn: E200033: database is locked解决办法

    svn执行update,却被告知database is locked! 执行 svn update,却抛出个错误警报: svn: E200033: database is locked, execut ...

  4. [Angular Directive] Structure directive and <template>

    The structure directive is just a sugar syntax of <template>. Such as: <div *ngIf="nam ...

  5. Erlang 进制转换

    http://www.cnblogs.com/me-sa/archive/2012/03/20/erlang0047.html bnot unary bitwise not integer div i ...

  6. 后台返回的HTML整个页面代码打开方法

    后台返回的html代码片段,需要插入html标签中,而返回的整个html文档,则需要重写整个页面. 解决方法: 需要一个中转页面,用document.write()方法重写整个页面: // POST任 ...

  7. Qt 静态函数QMetaObject::connectSlotsByName(QObject * object)

    看别人代码看到void on_MyWidget_slotTest(); 就郁闷了,没看到他代码里有connect 却能把信号和槽可以连接起来. 今日回顾书本发现该函所的nb之处. QMetaObjec ...

  8. NOIP 模拟 路径求和 - Tarjan+dfs+码

    题目大意: 各一个奇环内向森林,求每两个点对间的距离之和.无法到达则距离为-1. 分析: 首先Tarjan找出size大于1的连通分量(环),环中的边的贡献可以单独计算. 然后从入度为0的点向内dfs ...

  9. sparksql parquet 合并元数据

    java public class ParquetMergeSchema { private static SparkConf conf = new SparkConf().setAppName(&q ...

  10. JSP和Servlet学习笔记1 - 访问配置

    1. 访问 WebContent 目录下的 JSP 文件 在 WebContent 目录下的文件可以直接在浏览器中访问.新建一个 test.jsp 文件 <%@ page language=&q ...